English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP 基础教程

PHP 高级教程

PHP & MySQL

PHP 参考手册

PHP mysqli_stmt_errno() 函数用法及示例

PHP MySQLi Referenzhandbuch

mysqli_stmt_errno()函数返回最近一次语句调用的错误代码。

定义和用法

mysqli_stmt_errno()函数返回在执行最后一条语句期间,发生的错误的代码。

语法

mysqli_stmt_errno($stmt)

参数

序号参数及说明
1

stmt(必需)

这是一个表示语句的对象。

返回值

PHP mysqli_stmt_errno()函数返回一个整数值,该整数值表示从执行最后一条语句开始的错误代码。如果没有错误,则此函数返回0

PHP版本

此函数最初是在PHP版本5中引入的,并且可以在所有更高版本中使用。

Online-Beispiel

以下示例演示了mysqli_stmt_errno()函数的用法(面向过程风格),返回最近一次语句执行发生的错误代码

<?php
   $con = mysqli_connect("localhost", "root", "password", "mydb");
   mysqli_query($con, "CREATE TABLE myplayers(ID INT, First_Name VARCHAR(255), Nachname VARCHAR(255), Geburtsort VARCHAR(255), Land VARCHAR(255))");
   print("Tabelle erstellen.....\n");
   mysqli_query($con, "INSERT INTO myplayers values(1, 'Sikhar', 'Dhawan', 'Delhi', 'India')");
   print("Eingabezeile.....\n");
   $stmt = mysqli_prepare($con, "SELECT * FROM myplayers");
   mysqli_query($con, "DROP TABLE myplayers");
   //Anweisung ausführen
   mysqli_stmt_execute($stmt);
   //Fehlercode
   $code = mysqli_stmt_errno($stmt);
   print("Fehlercode: ").$code;
   //Anweisung beenden
   mysqli_stmt_close($stmt);
   //Verbindung schließen
   mysqli_close($con);
?>

Ausgabeergebnis

Tabelle erstellen.....
Eingabezeile.....
Error Code: 1146

Online-Beispiel

在面向对象风格中,此函数的语法为$stmt-> errno。以下是面向对象风格的此函数的示例-

<?php
   //建立连接
   $con = new mysqli("localhost", "root", "password", "mydb");
   $con -> query("CREATE TABLE myplayers(ID INT, First_Name VARCHAR(255), Nachname VARCHAR(255), Geburtsort VARCHAR(255), Land VARCHAR(255))");
   print("Tabelle erstellen.....\n");
   $con -> query("INSERT INTO myplayers values(1, 'Sikhar', 'Dhawan', 'Delhi', 'India')");
   print("Eingabezeile.....\n");
   $stmt = $con ->prepare("SELECT * FROM myplayers");
   $con ->query("DROP TABLE myplayers");
   //Anweisung ausführen
   $stmt->execute();
   //Fehlercode
   $code = $stmt ->errno;
   print("Fehlercode: ").$code;
   //Anweisung beenden
   $stmt->close();
   //Verbindung schließen
   $con->close();
?>

Ausgabeergebnis

Tabelle erstellen.....
Eingabezeile.....
Fehlercode: 1146

Online-Beispiel

Falls der zuletzt ausgeführte Anweisungsobjekt keine Fehler hat, gibt diese Funktion zurück0 :

<?php
   $con = mysqli_connect("localhost", "root", "password", "mydb");
   mysqli_query($con, "CREATE TABLE myplayers(ID INT, First_Name VARCHAR(255), Nachname VARCHAR(255), Geburtsort VARCHAR(255), Land VARCHAR(255))");
   print("Tabelle erstellen.....\n");
   query = "INSERT INTO myplayers values("1, 'Sikhar', 'Dhawan', 'Delhi', 'India'), (2, 'Jonathan', 'Trott', 'Cape Town', 'South Africa'), (3, 'Kumara', 'Sangakkara', 'Matale', 'Sri Lanka')";
   //Vorbereitete Anweisung
   $stmt = mysqli_prepare($con, $query);
   //Anweisung ausführen
   mysqli_stmt_execute($stmt);
   print("Eingabezeile.....\n");
   //Fehlercode
   $code = mysqli_stmt_errno($stmt);
   print("Fehlercode: ").$code;
   //Anweisung beenden
   mysqli_stmt_close($stmt);
   //Verbindung schließen
   mysqli_close($con);
?>

Ausgabeergebnis

Tabelle erstellen.....
Eingabezeile.....
Fehlercode: 0

PHP MySQLi Referenzhandbuch