Connecting to MySQL Databases with PHP

Use the following outline to connect and begin querying the mySQL server from within your PHP scripts. Remember that you cannot connect to your databases remotely for security reasons; you can only connect from localhost.

1. Connect To The mySQL Server
Use the following statement to connect to the database server. Substitute the username, and password for those that have been created in the PCP interface and have given adequate permissions to this database.


2. Select Your Database

Use the following statement to select the database you wish to connect to. Make sure you substitute your database name.


3. Executing A Query
You are now ready to execute your queries. Remember that the databases and users must be created in the MyAdmin interface in your PCP. Most problems that arise with your scripts will be caused by incorrect permission settings.