Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7583659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:44:05+00:00 2026-05-30T18:44:05+00:00

When having an error in SQL syntax in classic PHP mysql, the query will

  • 0

When having an error in SQL syntax in classic PHP mysql, the query will not take place without any other effect. But in mysqli, it will kill the PHP script with Fatal error

mysql_query("SELECT title, misspelled_column FROM posts");

$mysqli->query("SELECT title, misspelled_column FROM posts");

In the first case, it will show the other queries and php output; but the second case kills the script by

Fatal error: Call to a member function fetch_assoc() on a non-object

The problem is related to non-object returned by false query. I can skip this error by

if($result){$row = $result->fetch_assoc();}

but my question is that why I did not need this check in classic mysql? With a more advanced system, one expects new features not missing what we had.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T18:44:06+00:00Added an answer on May 30, 2026 at 6:44 pm

    An error generated by MySQL should not be stopping execution. In fact, you can have your script show you any SQL errors by using $mysqli->error (assuming $mysqli is your database connection, like in your example). However, what may be happening is that your mysqli error causes a particular object not to be created, and then calling a method on that object will create a fatal PHP error. For example:

    $dbconn = new mysqli("localhost", $username, $password, $dbname);
    $stmt = $dbconn->prepare("bluh"); // not a valid statement. fails to create a mysqli statement object in $stmt.
    echo($dbconn->error); // your script is still running, and this will show your MySQL syntax error.
    $stmt->execute();
    

    This will die not because you made an SQL error, but because $stmt was null and didn’t have the expected execute() method. So like everyone else has said, check your logs and see what the actual error is.

    Using @ to ignore errors is going to be hit-or-miss until you figure out which specific command is creating the error.

    update: If you know that the error is in the query, then you could check to see whether the query succeeded before you try to do anything with it. One way is to check the error parameter; another is to check to make sure that it actually returned the kind of object you want.

    Here are examples of both:

    $result = $db->query("select firstname, lastname from people where firstname = 'egbert';");
    if($db->error == '') {
         // the query worked, so fetch results from $result and do stuff with them.
    }
    else {
         // the query didn't work, so don't try to do anything with $result
    }
    
    // alternately:
    if(gettype($result) == "object") {
         // the query worked.
    }
    else {
         // it didn't.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some trouble with a SQL transaction using PHP and mySQL. Here is
i am having syntax error with the following sql statement the thing is i
I'm having an issue with a MySQL query when run in php. It works
I'm currently having following error message when executing a .sql file with about 26MB
I am having this error in my j2ee web application. java.sql.SQLException: ORA-00604: error occurred
I'm having a very confusing error between SharePoint and SQL Server 2k5. My SQL
here is the part if having error. Fatal error: Using $this when not in
I'm having an error where I am not sure what caused it. Here is
I am having an error: Error 2 'int[]' does not contain a definition for
I keep having an error when running my web application. The error does not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.