本文介紹了PDO 限制和偏移的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
可能的重復(fù):
PHP PDO bindValue 限制
在prepare語句中使用LIMIT和/或OFFSET時(shí)無法顯示數(shù)據(jù),但是如果我不使用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);
確實(shí)有效
這篇關(guān)于PDO 限制和偏移的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!