English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
PHP MySQLi Manuale di Referenza
The mysqli_errno() function returns the error code of the last function call
mysqli_errno()The function returns the error code that occurred during the last call to the mysqli function.
mysqli_errno($con)
Serial number | Parameters and descriptions |
---|---|
1 | con(必需) This is an object representing the connection with the MySQL Server. |
The mysqli_errno() function returns an integer value that represents the error code from the last MySQLi function call. If there is no error, this function returns0.
This function was initially introduced in PHP version 5 and can be used in all higher versions.
The following example demonstratesmysqli_errno()Usage of the function (procedural style)-
<?php //Establish connection $con = mysqli_connect("localhost", "root", "password", "mydb"); //Query to retrieve all rows from the employee table mysqli_query($con, "SELECT * FORM employee"); //Error code $error = mysqli_errno($con); print("Error occurred: ". $error); //Chiudi la connessione mysqli_close($con); ?>
Risultato di output
Error occurred: 1064
In the object-oriented style, the syntax of this function is$con-> errno. The following is an example of this function in an object-oriented style-
<?php //Establish connection $con = new mysqli("localhost", "root", "password", "mydb"); //Query to retrieve all rows from the employee table $con -> query("SELECT * FROM wrong_table_name"); //Error code $error = $con -> errno; print("Error occurred: ". $error); //Chiudi la connessione $con -> close(); ?>
Risultato di output
Error occurred: 1146
The following ismysqli_errno()Another example of a function-
<?php //Establish connection $con = mysqli_connect("localhost", "root", "password", "mydb"); //Query per selezionare tutte le righe della tabella employee mysqli_query($con, "SELECT * FROM employee"); print("Errore nella query SELECT: " . mysqli_errno($con) . "\n"); //Query per aggiornare una riga nella tabella Employee mysqli_query($con, "UPDATE employee set INCOME=INCOME+5000 where FIRST_NAME in (*)"); print("Errore nella query UPDATE: " . mysqli_errno($con) . "\n"); //Query per inserire una riga nella tabella Employee mysqli_query($con, "INSERT INTO employee VALUES (Archana, 'Mohonthy', 30, 'M', 13000, 106)"); print("Errore nella query INSERT: " . mysqli_errno($con) . "\n"); //Chiudi la connessione mysqli_close($con); ?>
Risultato di output
Errore nella query SELECT: 0 Errore nella query UPDATE: 1064 Errore nella query INSERT: 1054
Restituisce l'ultimo codice di errore chiamato dalla funzione chiamata di recente:
<?php $connection_mysql = mysqli_connect("localhost", "root", "password", "mydb"); if (mysqli_connect_errno($connection_mysql)){ echo "Connessione MySQL fallita: " . mysqli_connect_error(); } if (!mysqli_query($connection_mysql, "INSERT INTO employee (FirstName) VALUES ('Jack')")){ echo("Codice di errore: " . mysqli_errno($connection_mysql)); } mysqli_close($connection_mysql); ?>
Risultato di output
Codice di errore: 1054