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.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">