From:             jmat at shutdown dot net
Operating system: Linux 2.4.18/Redhat 7.2
PHP version:      4CVS-2003-08-07 (stable)
PHP Bug Type:     MySQL related
Bug description:  mysql_select_db returns 'true' when select failed

Description:
------------
When trying to select a database, about every 5 times, the database will
not get selected, and future queries will fail.  To make matters worse,
mysql_select_db is returning 'true' even when the database isn't selected.
 This code has worked since PHP 4.0, and has never changed; this problem
just started appearing on the latest CVS (had to upgrade to fix
ErrorDocument under Apache/2).

Attached code is pieced together from my database abstraction library; it
produces the same problems as my full code does.

I have verified there are no problems with the database server.

When I push this code back on to 4.3.2, I can't make it fail.

PHP Version 4.3.3RC3-dev 
Apache 2.0.47
MySQL Support Client API version 4.0.14 
MYSQL_MODULE_TYPE external 

for full phpinfo:  http://shutdown.net/~web/index.php


Reproduce code:
---------------
/* DEFINE's for server, server port, username, passwd */
define("SITE_DB","test");

$db_handle = mysql_pconnect(DB_SERVER.":".DB_PORT,DB_USER,DB_PASS))

$RETRY = 0;
while (!mysql_select_db(SITE_DB,$db_handle)) {
    logger("ERROR: Cannot select ".SITE_DB." database! ATTEMPT
$RETRY".mysql_error(),0);
    sleep(1);
    if ($RETRY++ > 5) {
        trigger_error("Couldn't select ".SITE_DB." on ".DB_SERVER,2);
        return false;
    }
}

$result = mysql_query("select count(*) from user");
if (mysql_error()) die("FAIL: ".mysql_error());
$value = mysql_result($result,0);
echo $value;

Expected result:
----------------
5

Actual result:
--------------
about 1/3 the time:
"FAIL:  No Database Selected"

the other 2/3:
"5"

-- 
Edit bug report at http://bugs.php.net/?id=24977&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=24977&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=24977&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=24977&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=24977&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=24977&r=needtrace
Try newer version:          http://bugs.php.net/fix.php?id=24977&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=24977&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=24977&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=24977&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=24977&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=24977&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=24977&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=24977&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=24977&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=24977&r=gnused

Reply via email to