简体   繁体   中英

mysqli_multi_query with CREATE TABLE and INSERT INTO

$query = "INSERT INTO abc VALUES ('1', '2', '3')";
$send_to_mysql = mysqli_query($connection, $query);

OK.

$query = "CREATE TABLE abc (a varchar(255), b varchar(255), c varchar(255))";
$send_to_mysql = mysqli_query($connection, $query);

OK.

$query = "CREATE TABLE abc (a varchar(255), b varchar(255), c varchar(255))";
$query .= "INSERT INTO abc VALUES ('1', '2', '3')";
$send_to_mysql = mysqli_multi_query($connection, $query);

nop. Where's the problem?

Put a semicolon between your two queries. As you are putting your two queries into one single string, you need to separate them in order for MySQL to understand that you do have two queries :

$query = "CREATE TABLE abc (a varchar(255), b varchar(255), c varchar(255));";
$query .= "INSERT INTO abc VALUES ('1', '2', '3')";

Put semicolon as separator between two queries like

$query = "CREATE TABLE abc (a varchar(255), b varchar(255), c varchar(255));";
mysqli_multi_query($connection, $query);
$query = "INSERT INTO abc VALUES ('1', '2', '3')";
$send_to_mysql = mysqli_multi_query($connection, $query);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM