1

I tried to run this query but it keep fails. Anyone know which part is wrong?

$query = "Select * FROM trade WHERE category = :categoryID order by id DESC limit :startID, 5";

$query_params = array(
    ':categoryID' => $_POST['categoryID'],
    ':startID' => $_POST['startID']
);


//execute query
try {
    $stmt   = $db->prepare($query);
    $result = $stmt->execute($query_params);
}
catch (PDOException $ex) {
    $response["success"] = 0;
    $response["message"] = "Database Error!";
    die(json_encode($response));
}
phoon
  • 369
  • 1
  • 6
  • 21
  • 1
    Fails with what? An error? Receiving an F on their report card? The computer catching on fire? You need to be more specific. Most SQL database give very precise error messages that indicate exactly where the problem occurs. – tadman Oct 17 '17 at 16:50
  • The best advice in the original question is to disable emulated prepares, by the way. Assuming you're using MySQL, it's better to run them on the server anyway. – Bytewave Oct 17 '17 at 16:53
  • @tadman it catch the PDOException error – phoon Oct 17 '17 at 17:00
  • @Bytewave this is a php file, I run this on server side – phoon Oct 17 '17 at 17:01
  • You catch it, but you don't even look at it. You just throw that error away. The key step you're missing is to have a look in there and see what your database had to say about your query. – tadman Oct 17 '17 at 17:01
  • @phoon I don't understand what you mean. I know it's a PHP file. That question covers the same problem you're having; I'm talking about running prepared statements on the MySQL server instead of letting PDO emulate prepares. As I said, disabling prepared statements will fix your issue. – Bytewave Oct 17 '17 at 17:05
  • @Bytewave thanks, I just read how to disable prepared statement. It is worked. – phoon Oct 17 '17 at 17:10

0 Answers0