Diablosblizz Posted May 22, 2010 Share Posted May 22, 2010 Okay so I'm making a script that requires two different databases to be queried / inserted into. Both are started in the same file: config.php. Here's the connections: $billing_connection = mysql_connect("localhost", "root", "12345"); $billing_select = mysql_select_db("atb_billing", $billing_connection); $mybb_connection = mysql_connect("localhost", "root2", "12345"); $mybb_select = mysql_select_db("blah", $mybb_connection); That works fine, no errors. The issue comes when I attempt to query one of the databases within the config.php file, as seen here: $select = mysql_query("SELECT * FROM `waiting_accounts` WHERE `adminver` = '0'", $billing_connection) or die(mysql_error()); It comes back throwing this error: Notice: Undefined variable: billing_connection in /var/www/html/functions.php on line 7 I have no idea why this doesn't work in the same file, although if I were to include the "config.php" and do the same thing it works perfectly fine with both databases. I've also tried to have a "functions.php" file that does all the MySQL functions that would be required in config.php, but alas I still get that error. The config.php file is include as I can get variables from it with no problem. Also, upon further investigation I've noticed that if I ignore the $billing_connection resource link then it defaults to the $mybb_connection database. I figure this is because of it being created last of the two. Please help me here, I have no idea why it doesn't like being called in the same page. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/202601-why-cant-i-do-this/ Share on other sites More sharing options...
Mchl Posted May 22, 2010 Share Posted May 22, 2010 Did you check variable scope? Quote Link to comment https://forums.phpfreaks.com/topic/202601-why-cant-i-do-this/#findComment-1062015 Share on other sites More sharing options...
Diablosblizz Posted May 23, 2010 Author Share Posted May 23, 2010 Oh jeez! I totally had no idea about this in PHP. I added global $billing_connection and it works fine! Thank you very much sir. Quote Link to comment https://forums.phpfreaks.com/topic/202601-why-cant-i-do-this/#findComment-1062136 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.