mysql_connect() and mysql_pconnect() both are working for database connection but with little difference. In mysql_pconnect(), ‘p’ stands for persistance connection.
When we are using mysql_connect() function, every time it is opening and closing the database connection, depending on the request .
But in case of mysql_pconnect() function,
First, when connecting, the function would try to find a (persistent) connection that’s already open with the same host, username and password. If one is found, an identifier for it will be returned instead of opening a new connection.
Second, the connection to the SQL server will not be closed when the execution of the script ends. Instead, the connection will remain open for future use (mysql_close() will not close connection established by mysql_pconnect()).
mysql_pconncet() is useful when you have a lot of traffice on your site. At that time for every request it will not open a connection but will take it from the pool. This will increase the efficiency of your site. But for general use mysql_connect() is best.
I think this is a very imp concept in case of Database Connectivity.
HTH
Nice information Shruti. In fact, I used it yesterday only. The difference between connection and persistent connection is useful for the programmers.
I think it is a good information. Keep it up!
You are right Sachin.
Thanks.
~ Shruti.
I used to use mysql_pconnect on a high traffic site [3 million page views / month] and when unique traffic was high we quickly ran out of connections to give out to clients, so be careful doing this on high traffic sites…
very nice answer. i am satisfied with this answer. thanks.
At Fisrt Thanks
I am satisfied with this answer.I used but never clear about pconnect.
Good work Shruti
Thanks!!!!!!!!!!!!!!!
Good work Shruti
Thanks!!!!!!!!!!!!!!!!
hi my name is mahalakshmi… can we be frnd
i am mca graduate ….hyd… nice work
Thanks for posting the difference clearly
it’s helps me aaaaa lot……….
I am satisfied with this answer…nice job….
Thanks for posting the difference clearly……Thanks
Hi Shruthi,
you have given nice information on mysql_connect() and mysql_pconnect(). You said when we use mysql_connect() it will simply establish and close the connection. and in case of mysql_pconnect() it will look for already opened connection with the same host, username and password. here i just wanna know what do you mean by host, username and password. you mean the registered user on the site or the web host from where the user trying to access the site.
Thanks for posting the difference clearly..thanks again
Very GOOOOOOOOOOOOOD