Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PHP PDO bug when trying to parameterize SQL LIMIT :initiallimit, :finallimit.
- 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
- 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_*:
- 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
- ______________________________________
- Here is the code
- ______________________________________
- <?php
- public function fetchSomeRows($conn, $table, $rowOrder, $direction, $initialLimit, $finalLimit){
- $this->sql .= "{$table} ORDER BY :roworder :direction LIMIT :initiallimit, :finallimit";
- $q = $conn->prepare($this->sql);
- $q->execute(array(':roworder' => $rowOrder,':direction'=>$direction,':initiallimit'=>$initialLimit,':finallimit'=>$finalLimit));
- $q->setFetchMode(PDO::FETCH_ASSOC);
- return $q;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement