#43947 [NEW]: mysql_select_db fails to select database using variables

From: Date: Sun, 27 Jan 2008 22:38:14 +0000
Subject: #43947 [NEW]: mysql_select_db fails to select database using variables
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-121582@lists.php.net to get a copy of this message
From: joel dot a dot villarreal at gmail dot com Operating system: Windows XP Service Pack 2 PHP version: 5.2.5 PHP Bug Type: MySQL related Bug description: mysql_select_db fails to select database using variables Description: ------------ When calling a function to connect to MySQL, while supplying a database name for mysql_select_db() through a variable defined at an include file, the database is not selected. Reproduce code: --------------- ## connection.cfg.php says: <? $MySQL_DatabaseName = "foo"; ?> ## main.php says: <? include("connection.cfg.php"); connect(); function connect() { global $MySQL_DatabaseName; mysql_connect("localhost", "root", "########"); mysql_select_db($MySQL_DatabaseName); $row = mysql_fetch_array(mysql_query("SELECT * FROM footable WHERE ID = 1"), MYSQL_ASSOC) or die(mysql_error()); print_r($row); } ?> Expected result: ---------------- Expected result is to obtain a view of the row's data through the print_r() function. Actual result: -------------- mysql_error() prints: "No database selected". PHP warns mysql_fetch_array() has been given an invalid MySQL result resource. -- Edit bug report at http://bugs.php.net/?id=43947&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=43947&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=43947&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=43947&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=43947&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=43947&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=43947&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=43947&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=43947&r=needscript Try newer version: http://bugs.php.net/fix.php?id=43947&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=43947&r=support Expected behavior: http://bugs.php.net/fix.php?id=43947&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=43947&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=43947&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=43947&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=43947&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=43947&r=dst IIS Stability: http://bugs.php.net/fix.php?id=43947&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=43947&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=43947&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=43947&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=43947&r=mysqlcfg

« previous php.bugs (#121582) next »