mysql_errno
Renvoie le codage numérique du message d'erreur dans l'opération MySQL précédente.
Nom de la fonction: mysql_errno ()
Version applicable: PHP 4, PHP 5, PHP 7
Utilisation: la fonction mysql_errno () est utilisée pour obtenir le code d'erreur de la dernière opération MySQL.
Syntaxe: int mysql_errno ([ressource $ link_identifier = null])
paramètre:
Valeur de retour: renvoie une valeur entière représentant le code d'erreur de l'opération MySQL la plus récente, et si aucune erreur ne se produit, renvoyez 0.
Exemple:
$conn = mysql_connect("localhost", "username", "password"); mysql_select_db("database", $conn); $query = "SELECT * FROM table"; $result = mysql_query($query); if(mysql_errno() != 0){ echo "MySQL 错误码:" . mysql_errno() . "<br>"; echo "MySQL 错误信息:" . mysql_error() . "<br>"; } else { // 执行成功的操作}
$conn1 = mysql_connect("localhost", "username1", "password1"); $conn2 = mysql_connect("localhost", "username2", "password2"); mysql_select_db("database1", $conn1); mysql_select_db("database2", $conn2); $query1 = "SELECT * FROM table1"; $query2 = "SELECT * FROM table2"; $result1 = mysql_query($query1, $conn1); $result2 = mysql_query($query2, $conn2); if(mysql_errno($conn1) != 0){ echo "MySQL 错误码:" . mysql_errno($conn1) . "<br>"; echo "MySQL 错误信息:" . mysql_error($conn1) . "<br>"; } else { // 执行成功的操作} if(mysql_errno($conn2) != 0){ echo "MySQL 错误码:" . mysql_errno($conn2) . "<br>"; echo "MySQL 错误信息:" . mysql_error($conn2) . "<br>"; } else { // 执行成功的操作}
Notes: