这是查询:
$fullDate = 2012-01-01;
$event = 'String';
$sql = $db->query("INSERT INTO agenda (date, event) VALUES ($fullDate, $event)");
它不执行,我做错了什么?
您必须引用插入的值:
$sql = $db->query("INSERT INTO agenda (date, event) VALUES ('$fullDate', '$event')");
如果您使用的是 PDO,则使用准备好的语句更安全:
$stmt = $db->prepare("INSERT INTO agenda (date, event) VALUES (?, ?)");
$stmt->execute(array($fullDate, $event));
$sql = $db->query("INSERT INTO agenda (date, event) VALUES ('$fullDate', '$event)'");
if (PEAR::isError($sql))
{
die($sql->getMessage());
}