我不知道我做错了什么。它不工作。
我对这个很感兴趣。我想不通。
$sql="INSERT INTO hr_daily_claim(date,
site,
from,
to,
rental,
vehicle,
claim_id,
parking,
beverages,
others)
VALUES(:date,
:site,
:from,
:to,
:rental,
:vehicle,
:claim_id,
:parking,
:beverages,
:others)";
$stmt = $db->prepare($sql);
$stmt->execute(array(
':date' => $date,
':site' => $site,
':from' => $from,
':to' => $to,
':rental' => $rental,
':vehicle' => $vehicle,
':claim_id' => $cliamId,
':parking' => $parking,
':beverages'=> $beverages,
':others' => $others ));
请有人帮助我。 它没有给我任何错误。但受影响的行数 = 0;根本不插入。
下面是表结构
`id` int(11) NOT NULL AUTO_INCREMENT,
`claim_id` varchar(45) DEFAULT NULL,
`date` varchar(10) DEFAULT NULL,
`site` varchar(45) DEFAULT NULL,
`from` varchar(45) DEFAULT NULL,
`to` varchar(45) DEFAULT NULL,
`rental` int(11) DEFAULT NULL,
`vehicle` int(11) DEFAULT NULL,
`parking` int(11) DEFAULT NULL,
`beverages` int(11) DEFAULT NULL,
`others` int(11) DEFAULT NULL,
`timestamp` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
最佳答案
from
, to
都是reserved words在 MySQL 中。你需要用反引号把它包起来。
$sql="INSERT INTO hr_daily_claim(
`date`,
`site`,
`from`, //<-------- This
`to`, //<-------- This
`rental`,
`vehicle`,
`claim_id`,
`parking`,
`beverages`,
`others`
)
旁注:':claim_id' => $cliamId,
中的 $cliamId
变量可能有拼写错误,应该读作 ':claim_id ' => $claimId,
,所以一定要检查一下,因为这些变量没有发布在你的问题中。
如果一个失败,您的整个查询将失败。另外需要注意的是 $claimId
和 $claimid
是不一样的。变量区分大小写。
关于php - PDO 插入不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22881089/