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.
How does PHP know where to look for MySQL database?(No path)
Moderator: General Moderators
-
tristanlee85
- Forum Contributor
- Posts: 172
- Joined: Fri Dec 19, 2003 7:28 am
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.
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.CallumD wrote:So PHP will look for MySQL server first, not for a specific database file?
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.
- dibyendrah
- Forum Contributor
- Posts: 491
- Joined: Wed Oct 19, 2005 5:14 am
- Location: Nepal
- Contact:
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
You'll need to use:
before you attempt to use data from any specific database
Code: Select all
mysql_select_db('dbname') or die('Could not select db')