【发布时间】:2011-10-15 04:33:58
【问题描述】:
我有一个简单的脚本,我已将其包含在此处。选择查询工作正常,但插入查询失败。我在我的 macbook 上运行 php、apache 和 mysql。
表 city_profile 具有 ID 作为自动增量主键。并且名称是非空的。
function testMySQL() {
$db = new mysqli('localhost', 'root', NULL, 'citee');
//$query = "select * from city_profile"; //this query works
$query = "insert into city_profile ('name','state','country') values ('charlotte','north carolina','usa')";
//whereas the above one fails..
$results = $db->query($query);
if($results) {
echo '<p>The query is successful.</p>';
}else {
echo '<p>The query is NOT successful.</p>';
}
//close the connection
$db->close();
}
【问题讨论】:
-
是的,但仅适用于字段名称,不适用于值,或者只是删除字段名称周围的单引号。