• 首页
  • vue
  • TypeScript
  • JavaScript
  • scss
  • css3
  • html5
  • php
  • MySQL
  • redis
  • jQuery
  • mysqli::errno()

    (PHP 5, PHP 7)

    返回最近函数调用的错误代码

    说明

    面向对象风格
    int $errno;
    过程化风格
    mysqli_errno(mysqli$link): int

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

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

    参数

    $link

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

    返回值

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

    范例

    Example #1mysqli->errnoexample

    面向对象风格

    <?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() 返回上一次 SQL 操作的 SQLSTATE 错误信息
    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