gpt4 book ai didi

php - PDO MySQL prepare->execute INSERT INTO 未出现在数据库中

转载 作者:行者123 更新时间:2023-11-28 23:45:10 25 4
gpt4 key购买 nike

出于安全原因,我正在编写一个程序来监控我拥有的一堆计算机。我正在尝试使用以下代码将用户数据存储在数据库中:

$con->prepare("INSERT INTO `myComputers` (`hwid`, `ip`, `pcname`, `username`, `os`, `country`, `first`) VALUES (:hwid, :ip, :pcname, :username, :os, :country, :first")->execute(
array(
':hwid' => $data_array['hwid'],
':ip' => $data_array['ip'],
':pcname' => $data_array['pcname'],
':username' => $data_array['username'],
':os' => $data_array['os'],
':country' => $data_array['country'],
':first' => $data_array['first']
)
);

我没有收到任何错误,但是当我查看我的数据库时,没有插入任何数据。我已经检查过 $data_array 中的每个项目实际上都设置了一些东西。这里还有我的 MySQL 数据库构建查询:

CREATE TABLE IF NOT EXISTS myComputers(
hwid VARCHAR(64) NOT NULL PRIMARY KEY,
ip VARCHAR(45) NOT NULL,
pcname VARCHAR(50) NOT NULL,
username VARCHAR(50) NOT NULL,
os VARCHAR(150) NOT NULL,
country CHAR(2) NOT NULL,
first int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

我已经坚持了好几个小时,不知道是什么导致了这个问题。任何帮助将不胜感激。

这是我正在解析的一些测试数据(我已经更改了我的 IP 地址):

blahblah
123.12.123.123
PotatoPC
MyPotato
Windows
AU
1447671823

最佳答案

:first") 处结束引号和括号问题") 它是 :first)")

所以整个语句就是

$con->prepare("INSERT INTO `myComputers` (`hwid`, `ip`, `pcname`, `username`, `os`, `country`, `first`) VALUES (:hwid, :ip, :pcname, :username, :os, :country, :first)")->execute(
array(
':hwid' => $data_array['hwid'],
':ip' => $data_array['ip'],
':pcname' => $data_array['pcname'],
':username' => $data_array['username'],
':os' => $data_array['os'],
':country' => $data_array['country'],
':first' => $data_array['first']
)
);

关于php - PDO MySQL prepare->execute INSERT INTO 未出现在数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33733705/

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