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

From: Date: Sun, 27 Jan 2008 22:40:01 +0000
Subject: #43947 [Opn]: mysql_select_db fails to select database using variables
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-121583@lists.php.net to get a copy of this message
ID: 43947 User updated by: joel dot a dot villarreal at gmail dot com Reported By: joel dot a dot villarreal at gmail dot com Status: Open Bug Type: MySQL related Operating System: Windows XP Service Pack 2 PHP Version: 5.2.5 New Comment: Just in case, these are the versions of the server components being used at the moment: PHP Version 5.2.5 MySQL 5.0.46 Apaache 2.2.6 Previous Comments: ------------------------------------------------------------------------ [2008-01-27 22:38:14] joel dot a dot villarreal at gmail dot com 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 this bug report at http://bugs.php.net/?id=43947&edit=1

« previous php.bugs (#121583) next »