简单的插入语句不能在PHP代码中工作。适用于MySQL Workbench
16lz
2021-01-22
I have a simple script which I have included here. the select query works fine but the insert query fails. I am running php, apache and mysql on my macbook.
我有一个简单的脚本,我在这里包含。 select查询工作正常但插入查询失败。我在我的macbook上运行php,apache和mysql。
The table city_profile has ID as a auto increment primary key. And name is a non-null.
表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();
}
1 个解决方案
#1
3
try to change this line:
尝试更改此行:
$query = "insert into city_profile ('name','state','country') values ('charlotte','north carolina','usa')";
into this:
$query = "insert into `city_profile` (`name`,`state`,`country`) values ('charlotte','north carolina','usa')";
更多相关文章
- shell脚本中mysqldump的基本使用
- 使用Powershell对MySQL运行SQL脚本
- 如何知道php脚本中的名称是指mysql表还是mysql视图
- 是一个mysql临时表,每个用户访问创建它的脚本是唯一的...?
- mysql启动脚本——指定数据目录并指定配置文件
- Spring Security ACL使用MySQL配置与数据库脚本
- MySql查询脚本,每月统计活动用户。
- MySQL导出和导入SQL脚本
- MySQL在Linux下Shell脚本操作命令