Mysql query in PHP with proper error detection

/ Published in: PHP
Save to your folder(s)

Dumps whole query so developer can see where is error. However it's potential security issue, exposing SQL commands to attacker. (Recommended to use only during development, replace message code with some custom error text)

Copy this code and paste it in your HTML
  1. $sql="select something from something_else";
  2. $res_id=mysql_query($sql);
  3. if (!$res_id) {
  4. $message = 'Invalid query: ' . mysql_error() . "\n";
  5. $message .= 'Whole query: ' . $sql;
  6. die($message);
  7. }

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.