How to get MySQLi error information in different environmentsMySQLi prepared statements error reportingCall to a member function bind_param() on a non-objectHow to display errors for my MySQLi query?Trying to get property of non-object MySQLi resultphp check and validate form input with mysql databaseWarning: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, boolean given?Can't handle SQL exception with try-catchmysqli INSERT INTO query blank rowsHow to debug mysqli_query?PHP MySQLi Fatal error: Call to a member function fetch_array() on a non-object inWhy do I get this function call error on an non-object when I am calling a function on an object?How do I get PHP errors to display?How do I get a YouTube video thumbnail from the YouTube API?error on mysqli preparemysqli prepared statement - nested function does not performmysqli: can it prepare multiple queries in one statement?an error and warning appearing in my php/mysqliMySQLi Call to a member function bind_param() on a non-object ErrorMySQLi Error for Querybind_param() error in mysqli query

Removing all characters except digits from clipboard

date -d 'previous Monday" to display the preceding Monday

Was there a contingency plan in place if Little Boy failed to detonate?

Would encrypting a database protect against a compromised admin account?

Why does the Earth follow an elliptical trajectory rather than a parabolic one?

Why should password hash verification be time consistent?

What does this quote in Small Gods refer to?

Why is PerfectForwardSecrecy considered OK, when it has same defects as salt-less password hashing?

How to make a language evolve quickly?

Is a vertical stabiliser needed for straight line flight in a glider?

Why are low spin tetrahedral complexes so rare?

spatiotemporal regression

Equivalent for "Make the jacket to the button"

How to efficiently lower your karma

What's the difference between const array and static const array in C/C++

Why do the non-leaf Nodes of Merkle tree need to be hashed?

Was Mohammed the most popular first name for boys born in Berlin in 2018?

How to slow yourself down (for playing nice with others)

We are two immediate neighbors who forged our own powers to form concatenated relationship. Who are we?

Program for finding longest run of zeros from a list of 100 random integers which are either 0 or 1

Is every story set in the future "science fiction"?

How to evaluate sum with one million summands?

Examples where existence is harder than evaluation

Can 'sudo apt-get remove [write]' destroy my Ubuntu?



How to get MySQLi error information in different environments


MySQLi prepared statements error reportingCall to a member function bind_param() on a non-objectHow to display errors for my MySQLi query?Trying to get property of non-object MySQLi resultphp check and validate form input with mysql databaseWarning: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, boolean given?Can't handle SQL exception with try-catchmysqli INSERT INTO query blank rowsHow to debug mysqli_query?PHP MySQLi Fatal error: Call to a member function fetch_array() on a non-object inWhy do I get this function call error on an non-object when I am calling a function on an object?How do I get PHP errors to display?How do I get a YouTube video thumbnail from the YouTube API?error on mysqli preparemysqli prepared statement - nested function does not performmysqli: can it prepare multiple queries in one statement?an error and warning appearing in my php/mysqliMySQLi Call to a member function bind_param() on a non-object ErrorMySQLi Error for Querybind_param() error in mysqli query






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








72















In my local/development environment, the MySQLi query is performing OK. However, when I upload it on my web host environment, I get this error:




Fatal error: Call to a member function bind_param() on a non-object in...




Here is the code:



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


To check my query, I tried to execute the query via control panel phpMyAdmin and the result is OK.










share|improve this question
























  • Can we see where are you initiating $mysqli variable ?

    – Rikesh
    Mar 26 '14 at 13:29











  • It could be that your MySQL user is lacking the privileges to do a SELECT query. Did you check that?

    – Amal Murali
    Mar 26 '14 at 13:30











  • What pops to mind is that there's no mysqli available or you provided wrong credentials to connect to MySQL.

    – N.B.
    Mar 26 '14 at 13:30

















72















In my local/development environment, the MySQLi query is performing OK. However, when I upload it on my web host environment, I get this error:




Fatal error: Call to a member function bind_param() on a non-object in...




Here is the code:



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


To check my query, I tried to execute the query via control panel phpMyAdmin and the result is OK.










share|improve this question
























  • Can we see where are you initiating $mysqli variable ?

    – Rikesh
    Mar 26 '14 at 13:29











  • It could be that your MySQL user is lacking the privileges to do a SELECT query. Did you check that?

    – Amal Murali
    Mar 26 '14 at 13:30











  • What pops to mind is that there's no mysqli available or you provided wrong credentials to connect to MySQL.

    – N.B.
    Mar 26 '14 at 13:30













72












72








72


20






In my local/development environment, the MySQLi query is performing OK. However, when I upload it on my web host environment, I get this error:




Fatal error: Call to a member function bind_param() on a non-object in...




Here is the code:



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


To check my query, I tried to execute the query via control panel phpMyAdmin and the result is OK.










share|improve this question
















In my local/development environment, the MySQLi query is performing OK. However, when I upload it on my web host environment, I get this error:




Fatal error: Call to a member function bind_param() on a non-object in...




Here is the code:



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


To check my query, I tried to execute the query via control panel phpMyAdmin and the result is OK.







php mysqli prepared-statement environment error-reporting






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 27 '18 at 11:57









Peter Mortensen

14k1987114




14k1987114










asked Mar 26 '14 at 13:27









siopaomansiopaoman

36334




36334












  • Can we see where are you initiating $mysqli variable ?

    – Rikesh
    Mar 26 '14 at 13:29











  • It could be that your MySQL user is lacking the privileges to do a SELECT query. Did you check that?

    – Amal Murali
    Mar 26 '14 at 13:30











  • What pops to mind is that there's no mysqli available or you provided wrong credentials to connect to MySQL.

    – N.B.
    Mar 26 '14 at 13:30

















  • Can we see where are you initiating $mysqli variable ?

    – Rikesh
    Mar 26 '14 at 13:29











  • It could be that your MySQL user is lacking the privileges to do a SELECT query. Did you check that?

    – Amal Murali
    Mar 26 '14 at 13:30











  • What pops to mind is that there's no mysqli available or you provided wrong credentials to connect to MySQL.

    – N.B.
    Mar 26 '14 at 13:30
















Can we see where are you initiating $mysqli variable ?

– Rikesh
Mar 26 '14 at 13:29





Can we see where are you initiating $mysqli variable ?

– Rikesh
Mar 26 '14 at 13:29













It could be that your MySQL user is lacking the privileges to do a SELECT query. Did you check that?

– Amal Murali
Mar 26 '14 at 13:30





It could be that your MySQL user is lacking the privileges to do a SELECT query. Did you check that?

– Amal Murali
Mar 26 '14 at 13:30













What pops to mind is that there's no mysqli available or you provided wrong credentials to connect to MySQL.

– N.B.
Mar 26 '14 at 13:30





What pops to mind is that there's no mysqli available or you provided wrong credentials to connect to MySQL.

– N.B.
Mar 26 '14 at 13:30












1 Answer
1






active

oldest

votes


















79














Sometimes your query fails and you don't know why. Hence it is very important to configure PHP and mysqli to report you every error.



How to get the error message in mysqli



First of all, always have this line before MySQLi connect in all your environments:



mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);


After that all MySQL errors will be transferred into PHP exceptions. Uncaught exception, in turn, makes a PHP fatal error. Thus, in case of a MySQL error, you'll get a conventional PHP error. That will instantly make you aware of the error cause. A stack trace will lead you to the exact spot where error occurred.



How to configure PHP in different environments



Here is a gist of my article on PHP error reporting:

Note that you have to be able to see PHP errors in general. And here indeed goes the matter of different environments:



You must set the corresponding configuration options to the following values




  • On a development server




    • error_reporting should be set to E_ALL value;


    • display_errors should be set to 1



  • On a production server




    • error_reporting should be set to E_ALL value;


    • display_errors should be set to 0


    • log_errors should be set to 1


How to actually use it?



Just remove any code that checks for the error manually, all those or die(), if ($result) and such. Just write your database interaction code right away



$stmt = $this->con->prepare("INSERT INTO table(name, quantity) VALUES (?,?)");
$stmt->bind_param("si", $name, $quantity);
$stmt->execute();


again, witohut any conditions around. If an error occurs, then it will be treated as any other error in your code. For example, on a development PC it sill just appear on screen. And for a live site you will need an error wrapper but that's a different story, completely irrelevant to mysqli and its errors.



What to do with the error message you get



After getting the error message, you have to read and comprehend it. It sounds too obvious, but learners often overlook the extreme helpfulness of the error message. Yet most of time it explains the problem pretty straightforward. Say, if it says that particular table doesn't exist, you have to check spelling, typos, letter case, credentials and such. Or, if it says there is an error in SQL syntax, then you have to examine your SQL. And the problem spot is right before the query part cited in the error messaage.



You have to also trust the error message. If it says that number of tokens doesn't match number of bound variables then it is so. The same goes for the absent tables or columns. Given the choice, whether it's your own mistake or the error message is wrong, always stick to the former. Again it sounds condescending, but hundreds of questions on this very site prove this advise extremely useful.



A list of what you should never do in regard of error eporting



  • Use error suppression operator (@)

  • Use die() or echo or any other function to print the error message on screen unconditionally. PHP can echo it all right already, no assistance is required.

  • Testing the query result manually (like if($result)) just makes no sense. Either your query failed and you will already get the error exception, or it was all right and there is nothing to test.

  • Use try..catch for echoing the error message. Again PHP can do it better, way better.





share|improve this answer

























  • That was fast. Thanks for the inputs masterful guru. I found the cause. Though it did not directly fix the problem, it lead me to the fix and I learned a very helpful technique from you too.

    – siopaoman
    Mar 26 '14 at 13:41







  • 1





    Out of curiosity, which one of the above guesses accidentally won?

    – Your Common Sense
    Mar 26 '14 at 13:43











  • All of the above inputs helped me. But your answer specifically zoomed on the cause. Thanks to all of you. :)

    – siopaoman
    Mar 26 '14 at 13:46






  • 2





    @aendeerei no, it's off topic for their question. All they need is a proper code that can be later used in any environment. If you don't trust me, please go to Meta and ask a question, "Should I write a full code review including PHP, mysql, HTML and Bootstrap in response to a "my code doesn't work" question.

    – Your Common Sense
    Oct 23 '17 at 8:20






  • 1





    @aendeerei exceptions and fatal errors are THE SAME. this is the point of all my articles

    – Your Common Sense
    Oct 23 '17 at 8:22












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f22662488%2fhow-to-get-mysqli-error-information-in-different-environments%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









79














Sometimes your query fails and you don't know why. Hence it is very important to configure PHP and mysqli to report you every error.



How to get the error message in mysqli



First of all, always have this line before MySQLi connect in all your environments:



mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);


After that all MySQL errors will be transferred into PHP exceptions. Uncaught exception, in turn, makes a PHP fatal error. Thus, in case of a MySQL error, you'll get a conventional PHP error. That will instantly make you aware of the error cause. A stack trace will lead you to the exact spot where error occurred.



How to configure PHP in different environments



Here is a gist of my article on PHP error reporting:

Note that you have to be able to see PHP errors in general. And here indeed goes the matter of different environments:



You must set the corresponding configuration options to the following values




  • On a development server




    • error_reporting should be set to E_ALL value;


    • display_errors should be set to 1



  • On a production server




    • error_reporting should be set to E_ALL value;


    • display_errors should be set to 0


    • log_errors should be set to 1


How to actually use it?



Just remove any code that checks for the error manually, all those or die(), if ($result) and such. Just write your database interaction code right away



$stmt = $this->con->prepare("INSERT INTO table(name, quantity) VALUES (?,?)");
$stmt->bind_param("si", $name, $quantity);
$stmt->execute();


again, witohut any conditions around. If an error occurs, then it will be treated as any other error in your code. For example, on a development PC it sill just appear on screen. And for a live site you will need an error wrapper but that's a different story, completely irrelevant to mysqli and its errors.



What to do with the error message you get



After getting the error message, you have to read and comprehend it. It sounds too obvious, but learners often overlook the extreme helpfulness of the error message. Yet most of time it explains the problem pretty straightforward. Say, if it says that particular table doesn't exist, you have to check spelling, typos, letter case, credentials and such. Or, if it says there is an error in SQL syntax, then you have to examine your SQL. And the problem spot is right before the query part cited in the error messaage.



You have to also trust the error message. If it says that number of tokens doesn't match number of bound variables then it is so. The same goes for the absent tables or columns. Given the choice, whether it's your own mistake or the error message is wrong, always stick to the former. Again it sounds condescending, but hundreds of questions on this very site prove this advise extremely useful.



A list of what you should never do in regard of error eporting



  • Use error suppression operator (@)

  • Use die() or echo or any other function to print the error message on screen unconditionally. PHP can echo it all right already, no assistance is required.

  • Testing the query result manually (like if($result)) just makes no sense. Either your query failed and you will already get the error exception, or it was all right and there is nothing to test.

  • Use try..catch for echoing the error message. Again PHP can do it better, way better.





share|improve this answer

























  • That was fast. Thanks for the inputs masterful guru. I found the cause. Though it did not directly fix the problem, it lead me to the fix and I learned a very helpful technique from you too.

    – siopaoman
    Mar 26 '14 at 13:41







  • 1





    Out of curiosity, which one of the above guesses accidentally won?

    – Your Common Sense
    Mar 26 '14 at 13:43











  • All of the above inputs helped me. But your answer specifically zoomed on the cause. Thanks to all of you. :)

    – siopaoman
    Mar 26 '14 at 13:46






  • 2





    @aendeerei no, it's off topic for their question. All they need is a proper code that can be later used in any environment. If you don't trust me, please go to Meta and ask a question, "Should I write a full code review including PHP, mysql, HTML and Bootstrap in response to a "my code doesn't work" question.

    – Your Common Sense
    Oct 23 '17 at 8:20






  • 1





    @aendeerei exceptions and fatal errors are THE SAME. this is the point of all my articles

    – Your Common Sense
    Oct 23 '17 at 8:22
















79














Sometimes your query fails and you don't know why. Hence it is very important to configure PHP and mysqli to report you every error.



How to get the error message in mysqli



First of all, always have this line before MySQLi connect in all your environments:



mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);


After that all MySQL errors will be transferred into PHP exceptions. Uncaught exception, in turn, makes a PHP fatal error. Thus, in case of a MySQL error, you'll get a conventional PHP error. That will instantly make you aware of the error cause. A stack trace will lead you to the exact spot where error occurred.



How to configure PHP in different environments



Here is a gist of my article on PHP error reporting:

Note that you have to be able to see PHP errors in general. And here indeed goes the matter of different environments:



You must set the corresponding configuration options to the following values




  • On a development server




    • error_reporting should be set to E_ALL value;


    • display_errors should be set to 1



  • On a production server




    • error_reporting should be set to E_ALL value;


    • display_errors should be set to 0


    • log_errors should be set to 1


How to actually use it?



Just remove any code that checks for the error manually, all those or die(), if ($result) and such. Just write your database interaction code right away



$stmt = $this->con->prepare("INSERT INTO table(name, quantity) VALUES (?,?)");
$stmt->bind_param("si", $name, $quantity);
$stmt->execute();


again, witohut any conditions around. If an error occurs, then it will be treated as any other error in your code. For example, on a development PC it sill just appear on screen. And for a live site you will need an error wrapper but that's a different story, completely irrelevant to mysqli and its errors.



What to do with the error message you get



After getting the error message, you have to read and comprehend it. It sounds too obvious, but learners often overlook the extreme helpfulness of the error message. Yet most of time it explains the problem pretty straightforward. Say, if it says that particular table doesn't exist, you have to check spelling, typos, letter case, credentials and such. Or, if it says there is an error in SQL syntax, then you have to examine your SQL. And the problem spot is right before the query part cited in the error messaage.



You have to also trust the error message. If it says that number of tokens doesn't match number of bound variables then it is so. The same goes for the absent tables or columns. Given the choice, whether it's your own mistake or the error message is wrong, always stick to the former. Again it sounds condescending, but hundreds of questions on this very site prove this advise extremely useful.



A list of what you should never do in regard of error eporting



  • Use error suppression operator (@)

  • Use die() or echo or any other function to print the error message on screen unconditionally. PHP can echo it all right already, no assistance is required.

  • Testing the query result manually (like if($result)) just makes no sense. Either your query failed and you will already get the error exception, or it was all right and there is nothing to test.

  • Use try..catch for echoing the error message. Again PHP can do it better, way better.





share|improve this answer

























  • That was fast. Thanks for the inputs masterful guru. I found the cause. Though it did not directly fix the problem, it lead me to the fix and I learned a very helpful technique from you too.

    – siopaoman
    Mar 26 '14 at 13:41







  • 1





    Out of curiosity, which one of the above guesses accidentally won?

    – Your Common Sense
    Mar 26 '14 at 13:43











  • All of the above inputs helped me. But your answer specifically zoomed on the cause. Thanks to all of you. :)

    – siopaoman
    Mar 26 '14 at 13:46






  • 2





    @aendeerei no, it's off topic for their question. All they need is a proper code that can be later used in any environment. If you don't trust me, please go to Meta and ask a question, "Should I write a full code review including PHP, mysql, HTML and Bootstrap in response to a "my code doesn't work" question.

    – Your Common Sense
    Oct 23 '17 at 8:20






  • 1





    @aendeerei exceptions and fatal errors are THE SAME. this is the point of all my articles

    – Your Common Sense
    Oct 23 '17 at 8:22














79












79








79







Sometimes your query fails and you don't know why. Hence it is very important to configure PHP and mysqli to report you every error.



How to get the error message in mysqli



First of all, always have this line before MySQLi connect in all your environments:



mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);


After that all MySQL errors will be transferred into PHP exceptions. Uncaught exception, in turn, makes a PHP fatal error. Thus, in case of a MySQL error, you'll get a conventional PHP error. That will instantly make you aware of the error cause. A stack trace will lead you to the exact spot where error occurred.



How to configure PHP in different environments



Here is a gist of my article on PHP error reporting:

Note that you have to be able to see PHP errors in general. And here indeed goes the matter of different environments:



You must set the corresponding configuration options to the following values




  • On a development server




    • error_reporting should be set to E_ALL value;


    • display_errors should be set to 1



  • On a production server




    • error_reporting should be set to E_ALL value;


    • display_errors should be set to 0


    • log_errors should be set to 1


How to actually use it?



Just remove any code that checks for the error manually, all those or die(), if ($result) and such. Just write your database interaction code right away



$stmt = $this->con->prepare("INSERT INTO table(name, quantity) VALUES (?,?)");
$stmt->bind_param("si", $name, $quantity);
$stmt->execute();


again, witohut any conditions around. If an error occurs, then it will be treated as any other error in your code. For example, on a development PC it sill just appear on screen. And for a live site you will need an error wrapper but that's a different story, completely irrelevant to mysqli and its errors.



What to do with the error message you get



After getting the error message, you have to read and comprehend it. It sounds too obvious, but learners often overlook the extreme helpfulness of the error message. Yet most of time it explains the problem pretty straightforward. Say, if it says that particular table doesn't exist, you have to check spelling, typos, letter case, credentials and such. Or, if it says there is an error in SQL syntax, then you have to examine your SQL. And the problem spot is right before the query part cited in the error messaage.



You have to also trust the error message. If it says that number of tokens doesn't match number of bound variables then it is so. The same goes for the absent tables or columns. Given the choice, whether it's your own mistake or the error message is wrong, always stick to the former. Again it sounds condescending, but hundreds of questions on this very site prove this advise extremely useful.



A list of what you should never do in regard of error eporting



  • Use error suppression operator (@)

  • Use die() or echo or any other function to print the error message on screen unconditionally. PHP can echo it all right already, no assistance is required.

  • Testing the query result manually (like if($result)) just makes no sense. Either your query failed and you will already get the error exception, or it was all right and there is nothing to test.

  • Use try..catch for echoing the error message. Again PHP can do it better, way better.





share|improve this answer















Sometimes your query fails and you don't know why. Hence it is very important to configure PHP and mysqli to report you every error.



How to get the error message in mysqli



First of all, always have this line before MySQLi connect in all your environments:



mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);


After that all MySQL errors will be transferred into PHP exceptions. Uncaught exception, in turn, makes a PHP fatal error. Thus, in case of a MySQL error, you'll get a conventional PHP error. That will instantly make you aware of the error cause. A stack trace will lead you to the exact spot where error occurred.



How to configure PHP in different environments



Here is a gist of my article on PHP error reporting:

Note that you have to be able to see PHP errors in general. And here indeed goes the matter of different environments:



You must set the corresponding configuration options to the following values




  • On a development server




    • error_reporting should be set to E_ALL value;


    • display_errors should be set to 1



  • On a production server




    • error_reporting should be set to E_ALL value;


    • display_errors should be set to 0


    • log_errors should be set to 1


How to actually use it?



Just remove any code that checks for the error manually, all those or die(), if ($result) and such. Just write your database interaction code right away



$stmt = $this->con->prepare("INSERT INTO table(name, quantity) VALUES (?,?)");
$stmt->bind_param("si", $name, $quantity);
$stmt->execute();


again, witohut any conditions around. If an error occurs, then it will be treated as any other error in your code. For example, on a development PC it sill just appear on screen. And for a live site you will need an error wrapper but that's a different story, completely irrelevant to mysqli and its errors.



What to do with the error message you get



After getting the error message, you have to read and comprehend it. It sounds too obvious, but learners often overlook the extreme helpfulness of the error message. Yet most of time it explains the problem pretty straightforward. Say, if it says that particular table doesn't exist, you have to check spelling, typos, letter case, credentials and such. Or, if it says there is an error in SQL syntax, then you have to examine your SQL. And the problem spot is right before the query part cited in the error messaage.



You have to also trust the error message. If it says that number of tokens doesn't match number of bound variables then it is so. The same goes for the absent tables or columns. Given the choice, whether it's your own mistake or the error message is wrong, always stick to the former. Again it sounds condescending, but hundreds of questions on this very site prove this advise extremely useful.



A list of what you should never do in regard of error eporting



  • Use error suppression operator (@)

  • Use die() or echo or any other function to print the error message on screen unconditionally. PHP can echo it all right already, no assistance is required.

  • Testing the query result manually (like if($result)) just makes no sense. Either your query failed and you will already get the error exception, or it was all right and there is nothing to test.

  • Use try..catch for echoing the error message. Again PHP can do it better, way better.






share|improve this answer














share|improve this answer



share|improve this answer








edited May 6 at 5:28

























answered Mar 26 '14 at 13:32









Your Common SenseYour Common Sense

133k21146256




133k21146256












  • That was fast. Thanks for the inputs masterful guru. I found the cause. Though it did not directly fix the problem, it lead me to the fix and I learned a very helpful technique from you too.

    – siopaoman
    Mar 26 '14 at 13:41







  • 1





    Out of curiosity, which one of the above guesses accidentally won?

    – Your Common Sense
    Mar 26 '14 at 13:43











  • All of the above inputs helped me. But your answer specifically zoomed on the cause. Thanks to all of you. :)

    – siopaoman
    Mar 26 '14 at 13:46






  • 2





    @aendeerei no, it's off topic for their question. All they need is a proper code that can be later used in any environment. If you don't trust me, please go to Meta and ask a question, "Should I write a full code review including PHP, mysql, HTML and Bootstrap in response to a "my code doesn't work" question.

    – Your Common Sense
    Oct 23 '17 at 8:20






  • 1





    @aendeerei exceptions and fatal errors are THE SAME. this is the point of all my articles

    – Your Common Sense
    Oct 23 '17 at 8:22


















  • That was fast. Thanks for the inputs masterful guru. I found the cause. Though it did not directly fix the problem, it lead me to the fix and I learned a very helpful technique from you too.

    – siopaoman
    Mar 26 '14 at 13:41







  • 1





    Out of curiosity, which one of the above guesses accidentally won?

    – Your Common Sense
    Mar 26 '14 at 13:43











  • All of the above inputs helped me. But your answer specifically zoomed on the cause. Thanks to all of you. :)

    – siopaoman
    Mar 26 '14 at 13:46






  • 2





    @aendeerei no, it's off topic for their question. All they need is a proper code that can be later used in any environment. If you don't trust me, please go to Meta and ask a question, "Should I write a full code review including PHP, mysql, HTML and Bootstrap in response to a "my code doesn't work" question.

    – Your Common Sense
    Oct 23 '17 at 8:20






  • 1





    @aendeerei exceptions and fatal errors are THE SAME. this is the point of all my articles

    – Your Common Sense
    Oct 23 '17 at 8:22

















That was fast. Thanks for the inputs masterful guru. I found the cause. Though it did not directly fix the problem, it lead me to the fix and I learned a very helpful technique from you too.

– siopaoman
Mar 26 '14 at 13:41






That was fast. Thanks for the inputs masterful guru. I found the cause. Though it did not directly fix the problem, it lead me to the fix and I learned a very helpful technique from you too.

– siopaoman
Mar 26 '14 at 13:41





1




1





Out of curiosity, which one of the above guesses accidentally won?

– Your Common Sense
Mar 26 '14 at 13:43





Out of curiosity, which one of the above guesses accidentally won?

– Your Common Sense
Mar 26 '14 at 13:43













All of the above inputs helped me. But your answer specifically zoomed on the cause. Thanks to all of you. :)

– siopaoman
Mar 26 '14 at 13:46





All of the above inputs helped me. But your answer specifically zoomed on the cause. Thanks to all of you. :)

– siopaoman
Mar 26 '14 at 13:46




2




2





@aendeerei no, it's off topic for their question. All they need is a proper code that can be later used in any environment. If you don't trust me, please go to Meta and ask a question, "Should I write a full code review including PHP, mysql, HTML and Bootstrap in response to a "my code doesn't work" question.

– Your Common Sense
Oct 23 '17 at 8:20





@aendeerei no, it's off topic for their question. All they need is a proper code that can be later used in any environment. If you don't trust me, please go to Meta and ask a question, "Should I write a full code review including PHP, mysql, HTML and Bootstrap in response to a "my code doesn't work" question.

– Your Common Sense
Oct 23 '17 at 8:20




1




1





@aendeerei exceptions and fatal errors are THE SAME. this is the point of all my articles

– Your Common Sense
Oct 23 '17 at 8:22






@aendeerei exceptions and fatal errors are THE SAME. this is the point of all my articles

– Your Common Sense
Oct 23 '17 at 8:22




















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f22662488%2fhow-to-get-mysqli-error-information-in-different-environments%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현