問題得到這個工作:MySQL中創建表 - PHP
我把這個查詢字符串(作爲變量):
"query" =>
"CREATE TABLE
users(
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
date_created DATETIME,
last_active DATETIME,
last_logged_in DATETIME,
first_name VARCHAR(255),
last_name VARCHAR(255),
email VARCHAR(255),
password VARCHAR(255),
permissions INT,
status SMALLINT
)"
到這個循環:
foreach($queryStrings as $queryString)
{
$query = Database::Query($queryString[ "query" ]);
if($query)
{
echo "Database table " . $queryString[ "name" ] . " successfully created<br />";
}
else
{
echo "Database table " . $queryString[ "name" ] . " failed to create<br />";
}
}
數據庫:查詢是在這裏:
public static function Query($query)
{
$query = self::$mysqli->real_escape_string(trim($query));
if ($query = self::$mysqli->prepare($query))
{
$query->execute();
$DatabaseQuery = new DatabaseQuery();
$DatabaseQuery->result = $query->get_result();
$DatabaseQuery->mysql_num_rows = $query->num_rows();
$query->close();
return $DatabaseQuery;
}
echo false;
}
它失敗闖過:
if ($query = self::$mysqli->prepare($query))
正在準備的字符串是在這裏:
CREATE TABLE \r\n users(\r\n id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,\r\n date_created DATETIME, \r\n last_active DATETIME,\r\n last_logged_in DATETIME,\r\n first_name VARCHAR(255),\r\n last_name VARCHAR(255),\r\n email VARCHAR(255), \r\n password VARCHAR(255), \r\n permissions INT, \r\n status SMALLINT\r\n)
乾杯隊友。可愛的作品! – Jimmyt1988
請將問題標記爲已解決(如果是),@JamesT – EirikO
意思是當你做到了,但我不能,因爲我不得不等待4分鐘。感謝您的提醒 :) – Jimmyt1988