I want to connect two databases, but I can't. This is what I have: <?php mysql_connect("localhost","root"); $mybbDb = mysql_select_db("mybb2"); //RevBB $revbbDb = mysql_select_db("newbb"); $users = mysql_query( "SELECT `uid` FROM `$mybbDb.myf_users`" )or die(mysql_error()); while($user = mysql_fetch_array($users)) { echo $user['uid']; } PHP: First off, I'm not using the Newbb database, and I don't need to right yet. The problem is, I can't connect to the MyBB2 database. Gives me: Incorrect table name '1.myf_users' Can someone help me? Thanks.
assuming that root has granted rights to access both db's you just need to login into one and then on your select do something like this : SELECT `uid` FROM `mybb2.myf_users Your problem is that your are getting the response mysql_db_select call into the var $revbbDb, and usually that is 1 or 0 , so you need to have a variable for your databases and use it that way kind of $dbname = "thedb" ; SELECT `uid` FROM `$dbname.myf_users
donmarcos is right, when the following line gets executed $mybbDb = mysql_select_db("mybb2"); Code (markup): the value 1 is stored in variable $mybbDb thus $mybbDb = 1 ; Code (markup): => when the select query is run $users = mysql_query("SELECT `uid` FROM `$mybbDb.myf_users`" Code (markup): it becomes $users = mysql_query("SELECT `uid` FROM `1.myf_users`" Code (markup): You may create 2 variables $db1 = mybb2; // and $db2 = newbb; // and Code (markup): Than create your select query as $users = mysql_query("SELECT `uid` FROM `$db1.myf_users`" Code (markup): Test it and let us know if that works for you!!!
No HTML here bro... HTML is coding, it works with browser to display the images and text that you see. PHP, is a server side language....probably has the most support, totally free, pretty much can't go wrong with learning it. PHP is programming (different from coding) as a certain action has to take place by the user for it to do its thing. SQL/PHP, would be a great language to learn, but start with HTML/CSS. As for the OP, declare both db's as a varibable as it was suggested. It will take care of your problem.
D-Fraz, You are using $mybbDb in a wrong way. If both database on the same server and the MySQL user has rights to both database then you can simply run your query as donmarcos suggested. But it is better to use variables instead of actual database names. It will help you in future when you move from one host to another.