Tag Archives: mysqli_error()

mysqli_ Error() has no return value (Fixed)

<?php
$mysqli=mysqli_connect('localhost','root','123','test');
if(mysqli_connect_errno()){
    printf("Connect failed:%s\n",mysqli_connect_error());
    exit();
}
else
{
    $sql="CREATE TABLE testTable(
    id int not null primary key auto_increment,
    testField varchar(20)
    )";
    $res=mysql_query($mysql,$sql);   //I wrote $mysqli as $mysql, so it doesn't operate on the specified database.
    var_dump($res);
    echo "<br/>";
    if($res===true){
        echo "Table testTable successfully created.";
    }   
    else{
       printf("Could not create table:%s\n",mysqli_error($mysqli));
    }   
    mysqli_close($mysqli);
}
?>

Output result: (mysqli_error() returns no error message)

The first argument to mysqli_query() should be $mysqli, but I wrote $mysql, which doesn’t exist. So mysqli_query() doesn’t actually find it
Specified database, so no table build operation is performed. So mysqli_error() does not return a value.

Since my VIM configuration is not complete, this error should be detectable by IDE syntax correction.
So an operation error to the database, and mysqli_error() does not return a value, could be a parameter error passed to mysqli_query().
Mysqli_error () returns an error from the last database operation. If the first parameter was written incorrectly, no operation was performed to the specified database
Error message.