我想弄清楚临时桌子是怎么工作的。但是,即使我从我的教程中复制和粘贴它,我也没有得到预期的结果。
有关更多信息,请参见下面的代码。目前,.php文件返回一个空白页(没有错误),而我希望它是:
1行插入。
我查找了错误代码,但发现临时表没有错误代码。
有人知道我做错了什么吗?
<?php
$link = mysqli_connect("localhost","xxx","xxx","xxx");
/* check connection */
if (mysqli_connect_errno())
{
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
mysqli_query($link, "CREATE TEMPORARY TABLE myCity (Name CHAR(30)");
$city = "'s Hertogenbosch";
$city = mysqli_real_escape_string($link, $city);
/* this query with escaped $city will work */
if (mysqli_query($link, "INSERT INTO myCity (Name) VALUES ('$city')"))
{
printf("%d Row inserted.\n", mysqli_affected_rows($link));
}
mysqli_close($link);
?>发布于 2013-11-07 14:06:27
这个对我有用
<?php
ini_set("display_errors",1);
error_reporting(E_ALL);
$mysqli = new mysqli("localhost", "root", "admin123", "test");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$mysqli->query("CREATE TEMPORARY TABLE CITIES (
id int(11) NOT NULL,
name varchar(64) NOT NULL
)");
//$mysqli->autocommit(FALSE);
$mysqli->query("INSERT INTO CITIES VALUES ('1', 'Bavaria')");
$mysqli->query("INSERT INTO CITIES VALUES ('2', 'Havana')");
//$mysqli->commit();
if ($result = $mysqli->query("SELECT * FROM CITIES LIMIT 10")) {
printf("Select returned %d rows.\n", $result->num_rows);
/* free result set */
$result->close();
}
//$mysqli->query("DROP TABLE CITIES");
$mysqli->close();记住,临时表只按会话存在,有时我们需要创建常规表,然后再截断.您必须考虑使用DBAL,如Doctrine或ADODb之类的.
发布于 2013-11-07 13:41:46
看起来您的sql创建中出现了错误。您缺少了一个结尾括号:")“
CREATE TEMPORARY TABLE myCity (Name CHAR(30)阿德里安。
https://stackoverflow.com/questions/19837230
复制相似问题