Advertisement
yuranmp

PHP PDO myql LIMIT not functioning

Feb 23rd, 2015
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.59 KB | None | 0 0
  1. PHP PDO bug when trying to parameterize SQL LIMIT :initiallimit, :finallimit.
  2.  
  3. I have a function that is supposed to query the database and return a limited amount of rows from a table. I am using PDO the problem is that
  4. I am getting an error even though I cannot find any errors on the syntax. Can anyone help me please? I have just started using PDO switching from the old mysql_*:
  5.  
  6. Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''0', '4'' at line 1' in /home/yuran/public_html/avec/DatabaseContent.php:30 Stack trace: #0 /home/yuran/public_html/avec/DatabaseContent.php(30): PDOStatement->execute(Array) #1 /home/yuran/public_html/avec/inc/header.php(43): DatabaseContent->fetchSomeRows(Object(PDO), 'topics', 'topic_id', 'DSC', 0, 4) #2 /home/yuran/public_html/avec/index.php(7): require_once('/home/yuran/pub...') #3 {main} thrown in /home/yuran/public_html/avec/DatabaseContent.php on line 30
  7. ______________________________________
  8. Here is the code
  9. ______________________________________
  10. <?php
  11. public function fetchSomeRows($conn, $table, $rowOrder, $direction, $initialLimit, $finalLimit){
  12. $this->sql .= "{$table} ORDER BY :roworder :direction LIMIT :initiallimit, :finallimit";
  13. $q = $conn->prepare($this->sql);
  14. $q->execute(array(':roworder' => $rowOrder,':direction'=>$direction,':initiallimit'=>$initialLimit,':finallimit'=>$finalLimit));
  15. $q->setFetchMode(PDO::FETCH_ASSOC);
  16.  
  17. return $q;
  18. }
  19.  
  20. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement