Suppose you now have an UPDATE statement, and sometimes the UPDATE statement is correct, but the number of rows affected is 0.
So how can you tell if the SQL statement is correct? Use of Mysqli_error ($Conn);
CREATE table User (name varchar (5), hobby text);
mysql> INSERT into user values ('Zhangsan', One,'test ....'); Query OK,1Row affected (0.01sec) MySQL> Update UserSetName='Zhangsan'; Query OK, 0 rows affected(0.00sec) Rows matched:1Changed:0Warnings:0MySQL> Update UserSetUsername='Zhangsan'; ERROR 1054(42S22): Unknown column'username' inch 'Field List'
To differentiate the above 2nd and 3rd SQL statements in PHP, use the following code:
$conn =mysqli_connect ($server _name, $username, $password, $database, $port); $sql = "Update user set Name= ' Zhangsan ' "; $res = Mysqli_query ($conn, $sql); if (Mysqli_error ($adsConn)) {echo mysqli_error ($adsConn);} else{echo "OK";}
PHP determines if the SQL statement is legitimate: Mysqli_error ()