【问题标题】:PDO PHP prepared and execute with UNIX_TIMESTAMP()PDO PHP 使用 UNIX_TIMESTAMP() 准备和执行
【发布时间】:2012-03-16 06:43:59
【问题描述】:

我在执行将项目插入 MYSQL 时遇到问题

我目前有这个代码

$save = $dbh->prepare("INSERT INTO tables(id,id2,datetime) VALUES(?,?,?)");
$save -> execute($id,$id2, "UNIX_TIMESTAMP()"); 

这给我带来了问题

PDOStatement::execute() expects at most 1 parameter, 3 given

【问题讨论】:

    标签: php mysql pdo prepared-statement unix-timestamp


    【解决方案1】:

    您不能将函数用作执行的参数。 此外,execute 只需要一个参数:一个数组,你给了 3 个参数。

    UNIX_TIMESTAMP() 必须直接写入查询,$id1,$id2 必须放入数组中

    $save = $dbh->prepare("INSERT INTO tables(id,id2,datetime) VALUES(?,?,UNIX_TIMESTAMP())");
    $save -> execute(array($id,$id2)); 
    

    【讨论】:

      【解决方案2】:

      与作为参数的函数无关,我遇到了同样的问题 我只是忘了将数据显示为 array() 项目...... 或者,您可以使用时间戳。

      而不是这个:

      $sec->execute($v,time(),$student_id);
      

      应该是这样的:

      $sec->execute(array($v,time(),$student_id));
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-07-20
        • 1970-01-01
        • 2016-07-17
        • 2016-11-19
        • 2014-09-16
        • 2017-10-26
        • 1970-01-01
        相关资源
        最近更新 更多