#1 How-To connect PHP and MySql?

This is my first How-To post in the category in an attempt to collect and solve all the small minor queries.

PHP is a scripting language and MySQL is an Open Source DBMS. Together they play a very vital role in developing the web based applications on GNU Linux platform/Windows.

Let me take you through a cakewalk of how to use PHP and MySQL and then the final verdict.

In order to run PHP and MySQL on your system you “must” have:

1. Apache { Web Server/LocalHost}

2. MySql { Database Management System}

3. PHP
4. GNU Linux / Windows

OR if you are running Windows on your system then you can even go for complete pack like:





// localhost will be the server ur trying to connect. username is understood and password for authentication.

$link = mysql_connect(‘localhost’, ‘username’, ‘password’);
if (!
) {
‘Could not connect: ‘ . mysql_error
‘Connected successfully’
// mysql_close will close the connection


This will help you in connecting with the MySQL database using PHP. This is an overview of general connection. In my next post I will teach u how to actually connect, retrive and then publish the data to the page.

Till then Happy Hacking!!!



If you are reading article, you might also be interested in the PHP and Scriptaculous Book I have authored.

The book gives you insights about effects, drag-n-drop, slideshows, applications, auto-completion, in-place editing and more. Complete code snippets and explanations.

CHECK out and BUY the PHP and Script.aculo.us book {My Book} at Packt official site


About srinix

I am Sridhar, a matured nut, on this planet with water, air and love ;)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: