$conn = new mysqli($serverName, $MYSQLUserName, $MYSQLPwd);
$sql = "use WA";
if($conn->query($sql)){
} else{
if($conn->error == "Unknown database 'wa'"){
$sqlCreateDatabase = "create database WA;";
$sqlCreateDatabase .= "alter database WA character set utf8;";
$conn->multi_query($sqlCreateDatabase);
$sqlCreateTable = "create table userInfo(
id smallint unsigned primary key auto_increment,
userName varchar(30),
pwd varchar(6)
);";
if($conn->query($sqlCreateTable)){
echo("success");
} else{
echo($conn->error);
}
}
}
Database WA was successfully created and the character set was also modified. But the data table could not be created successfully.
Error: Commands out of sync; you can't run this command now
Baidu did not find a solution. It said that the result set must be cleared first, but it did not succeed. Please help me.
The error obviously starts on line 14. Something should be released before line 14. Please tell me how to release this thing.
multi_query, don’t use this