文字

mysqli::errno

mysqli_errno

(PHP 5)

mysqli::errno -- mysqli_errno返回最近函数调用的错误代码

说明

面向对象风格

int $errno ;

过程化风格

int mysqli_errno ( mysqli $link )

返回最近的mysqli函数调用产生的错误代码.

客户端错误在Mysqlerrmsg.h头文件中列出, 服务端错误好在mysqld_error.h中列出. 在mysql源码分发包中的Docs/mysqld_error.txt你可以发现一个完整的错误消息和错误号.

参数

link

仅以过程化样式:由 mysqli_connect() mysqli_init() 返回的链接标识。

返回值

最后一次调用产生的错误代码, 返回0代表没有错误发生.

范例

Example #1 mysqli->errno example

面向对象风格

<?php
$mysqli 
= new  mysqli ( "localhost" "my_user" "my_password" "world" );


if ( mysqli_connect_errno ()) {
    
printf ( "Connect failed: %s\n" mysqli_connect_error ());
    exit();
}

if (!
$mysqli -> query ( "SET a=1" )) {
    
printf ( "Errorcode: %d\n" $mysqli -> errno );
}


$mysqli -> close ();
?>

过程化风格

<?php
$link 
mysqli_connect ( "localhost" "my_user" "my_password" "world" );


if ( mysqli_connect_errno ()) {
    
printf ( "Connect failed: %s\n" mysqli_connect_error ());
    exit();
}

if (!
mysqli_query ( $link "SET a=1" )) {
    
printf ( "Errorcode: %d\n" mysqli_errno ( $link ));
}


mysqli_close ( $link );
?>

以上例程会输出:

Errorcode: 1193

参见

  • mysqli_connect_errno() - Returns the error code from last connect call
  • mysqli_connect_error() - Returns a string description of the last connect error
  • mysqli_error() - Returns a string description of the last error
  • mysqli_sqlstate() - Returns the SQLSTATE error from previous MySQL operation

用户评论:

[#1] erwin at transpontine dot com [2013-06-28 05:31:11]

You can also find the error codes for for example MySQL 5.5 here: http://dev.mysql.com/doc/refman/5.5/en/error-handling.html

上一篇: 下一篇: