MySql php pdo 存储过程 PDOException: SQLSTATE[HY000]

MySql php pdo stored procedure PDOException: SQLSTATE[HY000]

他.

我在执行我的代码时收到此错误消息?我 post 从我的表格中取值“2020-12-19” $data_input_textfield = $_POST["date"];。不知道 1989 是从哪里来的...

留言:

Exception has occurred.
PDOException: SQLSTATE[HY000]: General error: 1525 Incorrect DATE value: '1989'

代码:

$sql = "CALL booking_date_input($data_input_textfield)";
    $stmt = $dbh->getInstance()->prepare($sql);
    $stmt->execute();
    $date=$stmt->fetch();

此致 /斯万特

您可以尝试一种稍微不同的方法,即为 sql 命令提供一个占位符,并使用绑定到该占位符的变量执行语句 - 如下所示:

$sql = "CALL `booking_date_input`(:date);";
$stmt = $dbh->getInstance()->prepare($sql);
$stmt->execute(array(':date'=>$data_input_textfield));
$date=$stmt->fetch();