如果我写这样的查询:
$conn = new mysqli($db_host, $db_username, $db_password, $db_database);
$conn -> query ("
DROP TABLE IF EXISTS for_search;
CREATE TABLE IF NOT EXISTS for_search
(
id INT,
for_search TEXT
);
");
$conn -> close();
它不起作用,但是如果我这样重写:
$conn = new mysqli($db_host, $db_username, $db_password, $db_database);
$conn -> query ("
DROP TABLE IF EXISTS for_search;
");
$conn -> query ("
CREATE TABLE IF NOT EXISTS for_search
(
id INT,
for_search TEXT
);
");
$conn -> close();
它将起作用! 我想知道为什么我不能在mysqli中编写多行查询吗?
答案 0 :(得分:1)
在mysqli中,您应该使用multi_query
来运行几个查询:
$conn = new mysqli($db_host, $db_username, $db_password, $db_database);
$conn -> multi_query ("
DROP TABLE IF EXISTS for_search;
CREATE TABLE IF NOT EXISTS for_search
(
id INT AUTOINCREMENT,
for_search TEXT
);
");
$conn -> close();