php - How to get mysqli error in different environments? -


in local/dev environment, mysqli query performing ok. however, when upload on webhost environment, got error;

fatal error: call member function bind_param() on non-object in...

here code:

global $mysqli; $stmt = $mysqli->prepare("select id, description tbl_page_answer_category cur_own_id = ?"); $stmt->bind_param('i', $cur_id); $stmt->execute(); $stmt->bind_result($uid, $desc); 

to check query, tried execute query via control panel phpmyadmin , result ok.

if there lacking information, please tell me can provide.

first of all, have line before mysqli connect in all environments:

mysqli_report(mysqli_report_error | mysqli_report_strict); 

after mysql errors transferred php exceptions. uncaught exception, in turn, makes php fatal error. thus, in case of mysql error, you'll conventional php error, instantly make aware of error cause. stack trace lead exact spot error occurred.

note have able see php errors in general. , here indeed goes matter of different environments:

  • on live site have peek error logs, so, settings have be

    error_reporting(e_all); ini_set('display_errors',0); ini_set('log_errors',1); 
  • while on local development server it's ok make errors on screen:

    error_reporting(e_all); ini_set('display_errors',1); 

and little list of should not:

  • use error suppression operator (@)
  • use die() or echo or other function print error message on screen unconditionally. php can echo right already, no assistance required.
  • test query result manually (like if($result)) makes no sense. either query failed , error exception, or right , there nothing test
  • use try..catch echoing error message. again php can better, way better.

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -