Categories

Connecting to MySQL Using PHP

You are here:
< All Topics

There are two main steps to connecting to a MySQL database using PHP.

First, connect to your MySQL server using the mysql_connect statement. For example:

$con = mysql_connect(‘HOSTNAME’,’USERNAME’,’PASSWORD’);

You can log in to your hosting account manager to find the hostname, user name, and password for your database.

Next, 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. Again, you can log in to your hosting account manager to find the name of your database. The name of your database is usually the same as the user name for that database.

From here, you can query your database using your PHP script. 

Previous Changing Your Desktop Notifier Settings
Next How do I import data into a MySQL database?
Table of Contents