In WAMP software stack, php and mysql are bundled together and we can use it with so much ease. To connect with mysql server we can use two ways one is phpMyAdmin and another is simple manually hand written code.
We will demonstrate the second option in this tutorial
The first step of any kind of connectivity is to check whether the connectivity has been established or not. To check the connectivity we need to know three things: The host name, Username, and respective Password.
Usually Host name is localhost, Username is root and password is " " (blank, unless you have changed the password at the time of installlation). By mentioning all these details we can connect a PHP page with MySQL server.
Following piece of code will help you to check whether your PHP web page has been connected with MySQL server or not
In the above coding you can see a special operator called Error Control Operator '@', this operator is completely optional, this operator is useful at the time when connection could not be established, if you use this operator at the time when connection could not be made, you will get following output:
If you don't use '@' symbol the output will be as follows:
Warning: mysqli_connect() [function.mysqli-connect]: (28000/1045): Access denied for user 'basu'@'localhost' (using password: NO) in C:\wamp\www\php\dbConn.php on line 2
NOTE: In the password section (right after user) do not put any space in between the single quote otherwise an error message would be generate, instead of valid user name.
Rs. 20,000 US$ 300
Today: Rs. 10,000 US$150
Course Duration: 30 hrs
Posted on: December 17, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles