可能的重复:
PHP PDO bindValue 限制
在prepare语句中使用LIMIT和/或OFFSET时无法显示数据,但是如果我不使用LIMIT和OFFSET,我可以显示雷磊",代码看起来有问题吗?
I could not display the data when using LIMIT and/or OFFSET in the prepare statement, but I can show "Lei Lei" if I don't use the LIMIT and OFFSET, does the code look wrong?
$statement = $conn->prepare("SELECT id,username FROM public2 WHERE username = :name LIMIT :sta OFFSET :ppage");
$name = "Lei Lei";
$statement->execute(array(':name' => $name,':sta' => $start,':ppage' => $per_page));
这与原来有效的代码有所不同:
This have been change from the original code which worked:
$query_pag_data = "SELECT id,username from public2 LIMIT $start, $per_page";
$result_pag_data = mysql_query($query_pag_data) or die('MySql Error' . mysql_error());
我找到了答案!
$statement->bindValue(':sta1', (int) $start, PDO::PARAM_INT);
确实有效
这篇关于PDO 限制和偏移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!