PDO LIMIT and OFFSET

Possible duplicate:
PHP PDO bindValue in LIMIT

I could not display the data when using LIMIT and / or OFFSET in the preparation instruction, but I can show "Lei Lei" if I do not use LIMIT and OFFSET, does the code look incorrect?

$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 was a change from the source code that 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()); 
+7
source share
3 answers

I found the answer!

 $statement->bindValue(':sta1', (int) $start, PDO::PARAM_INT); 

working

+16
source
 $dbh->setAttribute( PDO::ATTR_EMULATE_PREPARES, false ); 

allows you to bind variables without worrying about them.

+5
source

Edit: Fixed

 $statement = $conn->prepare("SELECT id,username FROM public2 WHERE username = :name LIMIT :limit OFFSET :offset"); $name = "Lei Lei"; $statement->bindValue(':name', $name); $statement->bindValue(':limit', (int) $start, PDO::PARAM_INT); $statement->bindValue(':offset', (int) $per_page, PDO::PARAM_INT); $statement->execute(); 
0
source

All Articles