Mysqli_connect vs mysqli_real_connect

I read the doumentation But I do not quite understand the difference.

What difference does the connection object make in this? I have not found any posts.

I misunderstood. Flags are not present in both. Why didn't they add flags as part of mysqli_connect ? Any specific reasons? Which one should I use?

+6
source share
3 answers

This function is different from mysqli_connect ():

 mysqli_real_connect() needs a valid object which has to be created by function mysqli_init(). With the mysqli_options() function you can set various options for connection. There is a flags parameter. 
+5
source

With mysqli_real_connect, you can check if the mysqli object initialization was successful and set mysqli_options before connecting.

+3
source

mysqli_real_connect() and mysqli_connect is different in that

mysqli_real_connect() accepts a lot more options than mysqli_connect

For example, I am creating a health check script for my Loadbalancer, and I want to set a very low connection timeout.

Now the connection timeout should be set using:

mysqli_options() with parameter name MYSQLI_OPT_CONNECT_TIMEOUT

Now the thing with mysqli_options() is that it should be called after mysqli_init () and before mysqli_real_connect ().

mysqli_connect cannot be used for this purpose.

Hope this explanation helps.

 <?php //create the object $connection = mysqli_init(); //specify the connection timeout $connection->options(MYSQLI_OPT_CONNECT_TIMEOUT, 3); //specify the read timeout $connection->options(MYSQLI_OPT_READ_TIMEOUT, 3); //initiate the connection to the server, using both previously specified timeouts $connection->real_connect('server', 'user', 'pass', 'database'); ?> 
0
source

All Articles