MySQL Forums
Forum List  »  PHP

Not sure what I'm doing wrong with this query
Posted by: Derek Rouleau
Date: July 23, 2012 05:06AM

This is the code I'm having a problem with:
//$sql = "SELECT SQL_CALC_FOUND_ROWS * FROM " . TBL_MEMBERS . " ORDER BY $order LIMIT :startRow, :numRows";
$sql = "SELECT SQL_CALC_FOUND_ROWS * FROM " . TBL_MEMBERS . " ORDER BY $order LIMIT $startRow, $numRows";

try {
$st = $conn->prepare( $sql );
$st->bindValue( ":startRow", $startRow, PDO::PARAM_INT );
$st->bindValue( ":numRows", $numRows, PDO::PARAM_INT );
$st->execute();
$members = array();
foreach ( $st->fetchAll() as $row ) {
$members[] = new Member( $row );
}

Ok, if I run the non-commented out version of the SQL it works fine and I get the result I expect, however if I run the commented out version I get the following error:

Query failed 1: 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 ''5'' at line 1

I printed this out at the start of the function to check the values:

startRow = 0 and numRows = 5

It looks like something around the last value as that is where the "5" is.

I'm sure it's something stupid as I only spend about 5 - 10 hours a month doing PHP, so thank you in advance!

oh yeah:

mysql> select version();
+-------------------------+
| version() |
+-------------------------+
| 5.5.24-0ubuntu0.12.04.1 |
+-------------------------+
1 row in set (0.00 sec)

Options: ReplyQuote


Subject
Written By
Posted
Not sure what I'm doing wrong with this query
July 23, 2012 05:06AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.