Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSSQL php pdo pagination, some thing wrong on bindParam

Working fine with MsSQL:

$ppage = 15;
$poset = 0;
$stmt = "SELECT * FROM tbl ORDER BY ID OFFSET {:$poset } ROWS FETCH NEXT {:ppage } ROWS ONLY";
$stmt = $this->conn->prepare($stmt);
$stmt->execute();
return $row = $stmt->fetchAll();

Not working fine with MsSQL:

$ppage = 15;
$poset = 0;
$stmt = "SELECT * FROM tbl ORDER BY ID OFFSET :poffset ROWS FETCH NEXT :perpage ROWS ONLY";
$stmt = $this->conn->prepare($stmt);
$stmt->bindParam(':poffset', $poset);
$stmt->bindParam(':perpage', $ppage);
$stmt->execute();
return $row = $stmt->fetchAll();

the query is fine with I use to run with variables actual data it works but it's not working when I set the variable by bindParam, when am I missing.

thanks in advance.

like image 943
SAR Avatar asked Jul 25 '16 04:07

SAR


1 Answers

Try using bindValue instead:

$stmt = $this->conn->prepare($stmt);
$stmt->bindValue(':poffset', $poset, PDO::PARAM_INT);
$stmt->bindValue(':perpage', $ppage, PDO::PARAM_INT);
$stmt->execute();
like image 81
mister martin Avatar answered Sep 22 '22 23:09

mister martin