Visit our FaceBook Page

Using MySQL with PHP

It is a very common thing to use MySQL for database management, PHP works well with MySQL and often these two are found together in website programming. 

This is for very good reason as both are native to Linux base web servers and most web servers come stock with these installed.

A few things to note before getting started...

MySQL is a seperate program than PHP so in order for PHP to perform functions such as querying a MySQL database, you must first determine a "connection".  This can be done with the following code:


Of course each of these variable are specific to your server and application, "$host" is most commonly "localhost" and "$dbUser" and "$dbPass" are usually set from cPanel in your phpAdmin.

Place this connection code in a file such as "config.php" and be sure to include it in any page that you intend to perform database queries with.

In the following articles, we will discuss some of the most common operations you will be likely to perform when using PHP to work with a MySQL database such as:

  • Querying database contents using the MySQL command "SELECT"
  • Inserting new data using "INSERT"
  • Modifying existing data using "UPDATE"
  • Deleting date using "DELETE"

While discussing each we will also talk about things such as ordering output, limiting results and matching data.