Asked 7 years ago
28 Feb 2017
Views 2270
pratik

pratik posted

Difference between mysqli_real_connect() and mysqli_connect() in PHP ?

what is Difference between mysqli_real_connect() and mysqli_connect() in PHP ?
pratik

pratik
answered Nov 30 '-1 00:00

php.net says ::


mysqli_real_connect() needs a valid object which has to be created by function mysqli_init().



it means
if you do connection with mysqli_connect() , you do not need to intialize it with mysqli_init()


$link = mysqli_connect("127.0.0.1", "my_user", "my_password", "my_db");

if (!$link) {
              echo "we re not connected";
}



but mysqli_real_connect uses object to initialize it , which return by mysqli_init


$link = mysqli_init();
 
if (!mysqli_real_connect($link, 'localhost', 'my_user', 'my_password', 'my_db')) {
    die('Connect Error (' . mysqli_connect_errno() . ') '
            . mysqli_connect_error());
}
Post Answer