PDO查询错误

时间:2014-05-11 21:15:24

标签: php pdo

为什么这条PHP行不起作用?

我正在使用PDO。

感谢。

-

if($arr['target_action']=="new") {
    $query = $pdo->prepare('INSERT INTO ___Bookings VALUES ("", ":hotel_id", ":BOO_RoomId", ":BOO_ClientId", ":BOO_DateCI", ":BOO_DateCO", ":BOO_Rate", "", "", "'.date('Y-m-d H:i:s').'", ":BOO_Status")');
    $query->execute(array(':BOO_RoomId' => $arr['rid'], ':BOO_ClientId' => $arr['BOO_ClientId'], ':BOO_DateCI' => $arr['cid'], ':BOO_DateCO' => $arr['cod'], ':BOO_Rate' => $arr['BOO_Rate'], ':BOO_Status' => $arr['BOO_Status'], ':hotel_id' => $_SESSION['CurrentLogged_HOT_HotelId'])); 
}

1 个答案:

答案 0 :(得分:1)

您需要删除占位符周围的引号。

if($arr['target_action'] == "new") {
    $query = $pdo->prepare("INSERT INTO ___Bookings VALUES ('', :hotel_id, :BOO_RoomId, :BOO_ClientId, :BOO_DateCI, :BOO_DateCO, :BOO_Rate, '', '', :Date, :BOO_Status)");
    $query->execute(array(':BOO_RoomId' => $arr['rid'], ':BOO_ClientId' => $arr['BOO_ClientId'], ':BOO_DateCI' => $arr['cid'], ':BOO_DateCO' => $arr['cod'], ':BOO_Rate' => $arr['BOO_Rate'], ':BOO_Status' => $arr['BOO_Status'], ':hotel_id' => $_SESSION['CurrentLogged_HOT_HotelId'], ':Date' => date('Y-m-d H:i:s'))); 
}

另外,为什么你在日期中使用字符串插值?!也可以使用占位符!