problem with a query and not sure why...
-
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 );
echo "sql string = " . $sql . "
";
echo "just before we hit the execute
";
$st->execute();
echo "just hit the execute
";
$members = array();
foreach ( $st->fetchAll() as $row ) {
echo "pre";print_r($row);echo "/pre";
$members[] = new Member( $row );
echo "pre";print_r($members);echo "/pre";
}ok had to remove the <> from the pre tags to makes it easier to read... 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 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)
-
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 );
echo "sql string = " . $sql . "
";
echo "just before we hit the execute
";
$st->execute();
echo "just hit the execute
";
$members = array();
foreach ( $st->fetchAll() as $row ) {
echo "pre";print_r($row);echo "/pre";
$members[] = new Member( $row );
echo "pre";print_r($members);echo "/pre";
}ok had to remove the <> from the pre tags to makes it easier to read... 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 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)
I figured it out... I checked the type of the variables and it thought the second was a string :doh: so I made some code changes and it's now a INT. Love those descriptive error messages, guess they have learned a few things from M$