PHP mysqli_sqlstate () function
Returns SQLSTATE error code of the last MySQL operation:
<?php // 假定数据库用户名:root,密码:123456,数据库:w3big $con=mysqli_connect("localhost","root","123456","w3big"); if (mysqli_connect_errno($con)) { echo "连接 MySQL 失败: " . mysqli_connect_error(); } // 数据表 websites 已存在,所以返回错误 $sql="CREATE TABLE websites (name VARCHAR(30),url VARCHAR(30),alexa INT)"; if (!mysqli_query($con,$sql)) { echo "SQLSTATE error: ". mysqli_sqlstate($con); } // 关闭连接 mysqli_close($con); ?>
Definition and Usage
mysqli_sqlstate () function returns the last error SQLSTATE error code.
The error code consists of five characters. "00000" indicating no error. Values are specified by ANSI SQL and ODBC.
grammar
mysqli_sqlstate( connection ) ;
参数 | 描述 |
---|---|
connection | 必需。规定要使用的 MySQL 连接。 |
technical details
return value: | Returns a string of the last error SQLSTATE error code contains. |
---|---|
PHP version: | 5+ |
PHP mysqli Reference Manual