Connecting to MySQL Using PHP
You can access MySQL databases directly through PHP scripts. This lets you read and write data to your database directly from your website.
To Connect to MySQL Using PHP
- Connect to your MySQL server using the
mysql_connectstatement. For example:$con = mysql_connect('HOSTNAME','USERNAME','PASSWORD');
For help with your
mysql_connectinformation, see Viewing Your Database Details with Shared Hosting Accounts.
- Select the database that you want to access using
mysql_select_db. For example:mysql_select_db('DATABASENAME', $con)Where
'DATABASENAME'is the name of your database — this also displays on your database's details page.
After establishing the connection and selecting the database, you can query it using PHP.
To help you create your own connection string, we've included an example below.