PDO PHP用UNIX_TIMESTAMP()编写并执行

问题描述:

I'm having problems with my execution for inserting item into MYSQL

I currently have this code

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

This gives me problems

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

我在将项目插入MYSQL时遇到问题 p>

我目前有这段代码 p>

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

这给我带来了问题 p>

  PDOStatement :: execute()最多需要1个参数,3个给定\  n  code>  pre> 
  div>

You just can't use a function as param with execute. Moreover, execute expects only one parameter : an array, you gave 3 parameters.

UNIX_TIMESTAMP() has to be written directly into the query and $id1,$id2 have to be put in an array

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

Matter not about function as param, the same problem I had I just forgot to show data as array() items... Either, you may use timestamp.

Instead of this:

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

One should be like this:

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