MySQLi - Connect Errno
语法
int mysqli_connect_errno ( void )
定义和用法
它返回上次连接调用的错误代码
示例
试试下面的例子 −
<?php $servername = "localhost:3306"; $username = "root"; $password = ""; $dbname = "TUTORIALS"; $conn = new mysqli($servername, $username, $password, $dbname); if ($conn->connect_error) { die("Connection failed: " . mysqli_connect_errno()); } echo "Database connected"; mysqli_autocommit($conn,FALSE); mysqli_query($conn,"INSERT INTO tutorials_auto (id,name) VALUES (10,'sai')"); mysqli_commit($conn); mysqli_close($conn); ?>
上述代码的示例输出应该是这样的 −
Database connected
在上面的示例中,如果您提供了错误的服务器身份验证详细信息,则会给出连接错误编号。