gpt4 book ai didi

php - PDO 插入不插入多个值

转载 作者:行者123 更新时间:2023-11-29 01:57:35 27 4
gpt4 key购买 nike

所以我有一些数据想用 PDO 输入。这是我的代码的样子

$DATA = $con->prepare("INSERT INTO users (key, ip) VALUES (:key, :ip)");
$DATA->bindValue(':ip', $ip, PDO::PARAM_STR);
$DATA->bindValue(':key', $key, PDO:PARAM_STR);
$DATA->execute();

问题是它不会进入数据库。只有当我像这样做一个值时它才有效

$DATA = $con->prepare("INSERT INTO users (key) VALUES (:key)");

这正常吗?我是否为每个变量做单独的陈述?

我的数据库

+-------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+------------------+------+-----+---------+----------------+
| id | int(11) unsigned | NO | PRI | NULL | auto_increment |
| key | varchar(255) | YES | | NULL | |
| ip | varchar(255) | YES | | NULL | |
+-------+------------------+------+-----+---------+----------------+

我得到了错误

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'key, ip) VALUES ('53a786577de99', 'E6pdpExv6q363baea9cba210afac6d7a556fca596e30c' at line 1' in /Users/mike/Desktop/Mail/index.php:37 Stack trace: #0 /Users/mike/Desktop/Mail/index.php(37): PDOStatement->execute() #1 {main} thrown in /Users/mike/Desktop/Mail/index.php on line 37

最佳答案

如果我记得的话,我认为 KEY 是一个保留字......试试回勾号。

关于php - PDO 插入不插入多个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24357332/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com