Friday, 10 May 2013

Open a Connection to the MySQL Server in PHP

 Basic syntex:

mysql_connect("hostname","usename","password","dbname")

Example:
<?php
     $con= mysql_connect("xyz.com","pan","pan123","my_db");
     if(!con){
          echo "Could not connect to database".mysql_connect_error();
         
      }
?>


2 comments:

Unknown said...

Hi Pankaj,

There is a bug in your code...You cannot use dbname in mysql_connect..
For that you have to use Mysqli to use that is mysqli_connect
Please switch to mysqli as mysql is going to be deprecated

Happy coding:)

Unknown said...

Thank you for all your help Dharmesh mallah......I have updated code as below
Basic syntex:
mysqli_connect("hostname","usename","password","dbname")
Example: