Won't connect to second db?

Codes here !

Moderators: macek, egami, gesf

Tony121076
New php-forum User
New php-forum User
Posts: 28
Joined: Fri Jan 03, 2003 4:00 pm

Won't connect to second db?

Postby Tony121076 » Sat Feb 01, 2003 3:11 pm

I connect to database "one", and my queries work great. Then I close the connection and connect to database "two", but now all of my queries are producing errors because they are asking for one.table instead of two.table NOTE: I have changed the database names, and cut out irrelevant code:

/* Connect to database two - this works fine */

$db = mysql_connect("localhost", "user", "pass");
mysql_select_db("one",$db);

/* Query db one - this works fine */

$query = "SELECT * FROM users";
$result = mysql_query($query);

$num = mysql_numrows($result);
$i=0;
while ($i < $num) {
...
++$i;
}
...
mysql_close();

/* Connect to database two - this doesn't produce errors */

$db = mysql_connect("localhost", "user", "password");
mysql_select_db("dbtwo",$db);


/* Query db two - produces error "Table 'one.serv' doesn't exist" WHY IS IT CALLING DB ONE? Please help*/

$query = "SELECT * FROM serv";
$result = mysql_query($query);
$num = mysql_numrows($result);

I changed the password to make sure that I was indeed connecting to db two, and I got "not connected to db errors, so I am connecting. Why is it still calling db one after my new select statement? Thank you for your time and attention.

User avatar
Joan Garnet
Moderator
Moderator
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars
Contact:

Postby Joan Garnet » Sat Feb 01, 2003 3:33 pm

Try this one:

Code: Select all

$db = mysql_connect("localhost", "user", "pass");
mysql_select_db("one",$db);

/* Query db one - this works fine */

$query = "SELECT * FROM users";
$result = mysql_query($query);

$num = mysql_numrows($result);
$i=0;
while ($i < $num) {
...
++$i;
}
...

/* Connect to database two - this doesn't produce errors */

mysql_select_db("dbtwo",$db);


/* Query db two - produces error "Table 'one.serv' doesn't exist" WHY IS IT CALLING DB ONE? Please help*/

$query = "SELECT * FROM serv";
$result = mysql_query($query);
$num = mysql_numrows($result);
mysql_close();


Return to “mySQL & php coding”

Who is online

Users browsing this forum: No registered users and 1 guest

cron