PDO 限制和偏移
可能的重复:
PHP PDO 绑定值在 LIMIT
使用 LIMIT 和/或 OFFSET 时无法显示数据在prepare语句中,但是如果我不使用LIMIT和OFFSET,我可以显示“Lei Lei”,代码看起来有问题吗?
$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));
这已从有效的原始代码更改为:
$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());
Possible Duplicate:
PHP PDO bindValue in LIMIT
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());
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我找到了答案!
确实有效
I found the answer!
does work
可以让你绑定变量而不必担心它们的类型
will let you bind variables without being bothered of them type
编辑:已修复
Edit: Fixed