Posted By

acosonic on 08/27/09


Tagged

mysql php


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

maxvee8
umang_nine
Rawrcasm
esritter


Mysql query in PHP with proper error detection


 / Published in: PHP
 

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)

  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  

You need to login to post a comment.