How do I use PHP to access my MySQL database?
Please note: This support article is a guide for our Linux users only.
The following article explains how to connect to a MySQL database using PHP. A MySQL database can be accessed on our servers using all of the programming languages available on the server. Unlike Perl, PHP contains native MySQL connection support, so it is not necessary to include a module.
In order to access your MySQL database with the PHP, please follow these steps:
- Log into your Linux web server via Secure Shell.
- Type the following connection string to connect to your database:
$link = mysql_connect('host', 'username', 'password') or die('Could not connect: ' . mysql_error());
mysql_select_db('database') or die('Could not select database');
- host: enter the MySQL server that you are assigned to, for example, mysql4.safesecureweb.com
- username: enter the username provided for your database
- password: enter the password provided for your database
- database: enter the name of the MySQL database