以下查詢適用於phpMyAdmin,但不能在php腳本中使用mysql或pdo。普通的select查詢可以在同一個php腳本中工作。如何從使用PDO或MySqli的臨時表中選擇行?
CREATE TEMPORARY TABLE tmptable1 (INDEX myindex (sid)) SELECT * FROM `table1` WHERE uid = 55 ORDER BY cc;
SELECT * FROM tmptable1 GROUP BY sid;
我有PHP版本5.5.0和mysqlnd一個LAMP服務器上5.0.11-dev的。
我在stackoverflow上閱讀,您不能使用pdo進行多個查詢。然而在this問題中描述了兩種方法都不適合我。
我嘗試使用此設置,但它不工作:
$db = new PDO("mysql:host=localhost;dbname=test", 'root', '');
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0);
$sql = "
DELETE FROM car;
INSERT INTO car(name, type) VALUES ('car1', 'coupe');
INSERT INTO car(name, type) VALUES ('car2', 'coupe');
";
try {
$db->exec($sql);
}
catch (PDOException $e)
{
echo $e->getMessage();
die();
}
我試圖通過計算器另一個答案建議另一種方法,但它表示,該功能是未知的:
$db = new PDO("mysql:host=localhost;dbname=test", 'root', '');
// works not with the following set to 0. You can comment this line as 1 is default
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1);
$sql = "
DELETE FROM car;
INSERT INTO car(name, type) VALUES ('car1', 'coupe');
INSERT INTO car(name, type) VALUES ('car2', 'coupe');
";
try {
$stmt = $db->prepare($sql);
$stmt->execute();
}
catch (PDOException $e)
{
echo $e->getMessage();
die();
}
如何獲取此查詢以從我的php腳本中獲取結果?
你完全是我的一天,它工作得很好,謝謝! – BastiaanWW