0

这是查询:

$fullDate = 2012-01-01;
$event = 'String';
$sql = $db->query("INSERT INTO agenda (date, event) VALUES ($fullDate, $event)");

它不执行,我做错了什么?

4

3 回答 3

4

您必须引用插入的值:

$sql = $db->query("INSERT INTO agenda (date, event) VALUES ('$fullDate', '$event')");
于 2012-09-22T11:38:25.370 回答
1

如果您使用的是 PDO,则使用准备好的语句更安全:

$stmt = $db->prepare("INSERT INTO agenda (date, event) VALUES (?, ?)");
$stmt->execute(array($fullDate, $event));
于 2012-09-22T11:41:48.340 回答
0
$sql = $db->query("INSERT INTO agenda (date, event) VALUES ('$fullDate', '$event)'");

if (PEAR::isError($sql)) 
{ 
die($sql->getMessage()); 
}
于 2012-09-22T11:41:55.113 回答