Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PDO LIMIT and OFFSET [duplicate]

Tags:

php

pdo

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());
like image 669
proyb2 Avatar asked Apr 01 '11 03:04

proyb2


2 Answers

I found the answer!

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

does work

like image 85
proyb2 Avatar answered Sep 22 '22 15:09

proyb2


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

will let you bind variables without being bothered of them type

like image 29
Your Common Sense Avatar answered Sep 21 '22 15:09

Your Common Sense