Connecting PHP to MySQL

This tutorial will demonstrate how to connect your PHP script to a MySQL database. PHP provides a set of functions which makes your task of connecting to a database easier than you’d imagine. Initially, we will need the following set of functions to connect to a database.
mysql_connect($host,$username,$password): Connects to the host.
mysql_select_db($database_name): Connects to the specified database
mysql_query($query): Executes the specified sql query. It returns the query handler which can be used to extract data from the query result using mysql_fetch_array() function.

In the following example, we have connected to a database and listed all the entries fro

Output:
output

The following two tabs change content below.