2
我有一个简单的脚本,我已经包括在这里。选择查询工作正常,但插入查询失败。我在我的macbook上运行php,apache和mysql。简单的插入语句不能在PHP代码中工作。从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();
}
改变'''入' – diEcho
是的,但仅限于字段名,而不是价值,或者只是删除字段名称的单引号。 – stivlo
谢谢...它的工作原理。 – edorahg