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

  • SEARCH
  • Home
  • 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 5983515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:14:32+00:00 2026-05-22T22:14:32+00:00

According to the manual of mysql_query() and to everything I know about this function

  • 0

According to the manual of mysql_query() and to everything I know about this function that I used so many times, it can either return a resource or FALSE if the query is a SELECT. Yet it returns TRUE from time to time.

How can this be? It never ever happened before. Is this a bug in PHP 5.3.2? Does anyone know anything about this?

The code is something like:

if (!$resource = mysql_query($query, $handle)) {
    throw some exception;
}

var_dump($query);
if ($resource === true && strpos($query, 'SELECT') !== false) {
    throw new Exception('mysql_query() returned TRUE for SELECT');
}

It’s pretty hard to reproduce, too. It happens only from time to time. I also noticed that it’s likely this happens at the same time the server interrupts the connection suddenly, in which case it should return FALSE…

  • 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-22T22:14:32+00:00Added an answer on May 22, 2026 at 10:14 pm

    If webbiedave isn’t on the right track, there’s only one codepath that allows for this situation in the php source:

    #if MYSQL_VERSION_ID < 32224
    #define PHP_MYSQL_VALID_RESULT(mysql)       \
        (mysql_num_fields(mysql)>0)
    #else
    #define PHP_MYSQL_VALID_RESULT(mysql)       \
        (mysql_field_count(mysql)>0)
    #endif
    

    …

    if (!mysql_result) {
        if (PHP_MYSQL_VALID_RESULT(mysql->conn)) { /* query should have returned rows */
            php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to save result set");
            RETURN_FALSE;
        } else {
            RETURN_TRUE; // <<< this case
        }
    }
    

    I would consider this a bug. Especially since there’s no real way to verify this – mysql_num_fields in the PHP code uses the resource that you’re not getting, not the connection.

    Although it’s still weird that the C version of mysql_query returns zero on lost connection – if you’re able to, try the following patch and reinstall the mysql extension:

    Index: ext/mysql/php_mysql.c
    ===================================================================
    --- ext/mysql/php_mysql.c       (revision 311719)
    +++ ext/mysql/php_mysql.c       (working copy)
    @@ -1485,6 +1485,9 @@
                    if (PHP_MYSQL_VALID_RESULT(mysql->conn)) { /* query should have returned rows */
                            php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to save result set");
                            RETURN_FALSE;
    +               } else if( mysql_errno(mysql->conn) != 0 ) {
    +                       php_error_docref("http://www.mysql.com/doc" TSRMLS_CC, E_WARNING, "%s", mysql_error(mysql->conn));
    +                       RETURN_FALSE;
                    } else {
                            RETURN_TRUE;
                    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

According to this link: http://logback.qos.ch/manual/appenders.html (in RollingFileAppender) It seems to me that Logback provides
According to this manual I can include scripts as binary data and load them
According to the PHP manual , a class like this: abstract class Example {}
According to HG manual : By default this command prints revision number and changeset
According to the jQuery manual you can send extra parameters (as an array) when
According to: http://www.php.net/manual/en/function.filectime.php In most Unix filesystems, a file is considered changed when its
I realized we can work at shared DOM ( according to manual ) from
According to this manual I tried to set the proxy extension. In my_prof_dir/extensions there
According to the manual: User variables... cannot be used directly in an SQL statement
Issue is that I can't change a column type to 'Text' This is the

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.