A brief tutorial on connecting PHP and MySQL

Posted by kumarjit in Software, Web Design Tutorials

1 Star2 Stars (No Ratings Yet)

A brief tutorial on connecting PHP and MySQL

The need to interact with your target customers has prompted websites to undergo a major evolution. Now, web admins try to collect as much data as possible from the visitors of their site for better communication. Therefore, a number of tools and applications have been developed which connects the website (what visitors see) and the back end database (where user data is stored). The combination of PHP-MySQL is one such application that is simple and extremely easy to implement.

Here, we will go through the basic steps of connecting the PHP script to the MySQL database

Mention the configuration details

Three important parameters must be mentioned in form of PHP variables for use at multiple places

a. The host name of the MySQL server (generally localhost)
b. User name of the server
c. Password (if any)

Connecting to MySQL

The connection happens after the following line is executed:

$connection = mysql_connect (hostname, username, password) or die (“Some error”);

Selecting the database

Once connected to the MySQL server, the concerned database has to be chosen using the following script:

mysql_select_db(database name);

Once this is done, other SQL functions can be easily used and the results would reflect on the connected database.

BounceWeb has great plans for PHP-MySQL hosting!

Be Sociable, Share!

Leave a Reply

You must be logged in to post a comment.