Cyclone
Cyclone

Reputation: 18295

MySQL Database doesn't exist, queries are automatically shunted to the correct db?

This is quite odd, but I have a script that was until now calling queries on a db that existed only on another server, and is now on my new server with a different name. However, the "host" was always localhost. The user connected to the non-existent DB on localhost, and somehow connected to the existing database instead?

Can someone please explain to me how everything is working properly even though it most certainly should not be? There is only one database currently.

Thanks for explaining, I'm confused.

Upvotes: 3

Views: 200

Answers (5)

Jasper
Jasper

Reputation: 11908

As I said, just a guess, but if the database user only has access to the correct database, it could be that it automatically selects that database.

No known facts here, just what I think could be involved (which is why I originally posted this as a comment rather than solution).

Upvotes: 1

Brian Driscoll
Brian Driscoll

Reputation: 19635

Keep in mind that your PHP code runs on the SERVER, not the client machine, so "localhost" as the host parameter in your mysql_connect call will work as long as the PHP code is executing on the same physical or virtual server as your MySQL db.

Upvotes: 0

Patriotec
Patriotec

Reputation: 399

If it was always localhost then the db was on that system. Localhost refers to the ip address 127.0.0.1 which is a non-routable ip address. Since it's a non-routable ip address it won't redirect to another computer unless you do it manually. For instance, under Windows hosts file, you can make localhost another ip address besides 127.0.0.1. That would be the only way for localhost to redirect to another computer

Upvotes: 0

dockeryZ
dockeryZ

Reputation: 3981

When you say another server? Do you mean another WAMP installation? Or an entirely different computer/operating system.

the "host" was always localhost.

That's the only reason I ask, because perhaps you still have the previous mysql server installed and the "New" one made home on a different non-default port.

Upvotes: 0

m1tk4
m1tk4

Reputation: 3467

First you connect to the MySQL server, then the database selection happens. If the database you are trying to select does not exist, the default database for this user remains selected. If only one database is accessible for a user, this database will be selected.

Upvotes: 1

Related Questions