Page 1 of 1
How does PHP know where to look for MySQL database?(No path)
Posted: Mon Jul 24, 2006 10:51 pm
by CallumD
Hi all,
I am running a distribution (Uniform Server 3.3), so I am coding in a development environment.
When I call a database from within PHP code, eg:
@mysql_connect("localhost", "username", "password")
How does it know the path to the database file? Will the database file need to be sitting in the same folder as the PHP files?
Thanks.
Posted: Mon Jul 24, 2006 11:03 pm
by tristanlee85
The MySQL database is a seperate service running on a server, usually the same server as your web server. When it tried to connect to MySQL using "localhost' and the username and password specifiied, it'll try to make a connection to MySQL on the same host that the server is being ran from. If it can connect, it will use the username and password to login giving you access to your SQL tables.
Posted: Mon Jul 24, 2006 11:07 pm
by CallumD
So PHP will look for MySQL server first, not for a specific database file?
Posted: Mon Jul 24, 2006 11:08 pm
by feyd
PHP doesn't care where MySQL stores the files, that's MySQL's job.
Posted: Mon Jul 24, 2006 11:14 pm
by Benjamin
CallumD wrote:So PHP will look for MySQL server first, not for a specific database file?
PHP doesn't have access to the database files. Granted it may be possible to write a script that attempts to access them, bypassing the MySQL server.
PHP connects to the database server through a socket, effectively logging in using the credentials you supply. Once a database connection has been established, you can send commands and receive results by using PHP functions which communicate with the server though this connection.
Posted: Tue Jul 25, 2006 1:42 am
by dibyendrah
if mysql server is in any other host and running on some other port rather than default port, you can also put the port in 4th parameter as well.
mysql_connect(IP_OR_Host, Username, Password, PORT);
Posted: Tue Jul 25, 2006 3:22 am
by Ollie Saunders
You'll need to use:
Code: Select all
mysql_select_db('dbname') or die('Could not select db')
before you attempt to use data from any specific database