$db = new PDO();$sth = $db->prepare('sql');// 有木有一个类似getSql的方法可以获取执行的SQL的= =
And then
$db = new PDO();$sth = $db->prepare('select * from `table` where p1 = :p1 limit :limit');$sth->bindValue(':p1',$var_p1,PDO::PARAM_INT);$sth->bindValue(':limit',$var_limit,PDO::PARAM_INT);# ^ 这样正确$sth->execute(array(intval($var_p1),intval($var_limit));# ^ 为毛报错?,execute中,转成int还是不行?非要我指定一个绑定类型?
Reply content:
$db = new PDO();$sth = $db->prepare('sql');// 有木有一个类似getSql的方法可以获取执行的SQL的= =
And then
$db = new PDO();$sth = $db->prepare('select * from `table` where p1 = :p1 limit :limit');$sth->bindValue(':p1',$var_p1,PDO::PARAM_INT);$sth->bindValue(':limit',$var_limit,PDO::PARAM_INT);# ^ 这样正确$sth->execute(array(intval($var_p1),intval($var_limit));# ^ 为毛报错?,execute中,转成int还是不行?非要我指定一个绑定类型?
Not a type of problem, take a closer look at the documentation: http://cn2.php.net/manual/zh/pdostatement.execute.php
You do this by using the question-mark placeholder when you use the Execute call method, and if you use the "Colon parameter name", the array passed at Execute will also use the colon-argument-prepare to set the subscript.
Also, do you want to get the SQL statement after replacing the placeholder with the actual parameter value? PDO is impossible because prepared statement is essentially a temporary stored procedure