What is the advantge and disadvantage of mysql_connet() and
mysql_pconnect() ? in which condition will you use
mysql_connect() and mysql_pconnect().

Answers were Sorted based on User's Feedback



What is the advantge and disadvantage of mysql_connet() and mysql_pconnect() ? in which condition w..

Answer / praveen

mysql_pconnect() will maintain a persistent connection to
the database. whenever your script calls the connect to
database function, it first searches already existing
connections to the database and if exists it will use the
same connection to connect to the database, if not it will
open a new connection to the database. ie. Connection is
Persistent

where as mysql_connect() function will establish a new
connection whenever a connection to database needed, and
after executing the script, this function disconnects the
connection. ie. connection is not a persistent one.

mysql_pconnect() function is used where your site has a
Heavy Traffic and where as mysql_connect() function is used
when there is moderate/less traffic to your site.

Is This Answer Correct ?    10 Yes 1 No

What is the advantge and disadvantage of mysql_connet() and mysql_pconnect() ? in which condition w..

Answer / ltmert

If you're connecting to a MySQL database in your PHP
application, you'll find that there are two alternative
connctions - mysql_connect which establishes a new
connection "each time" and mysql_pconnect which uses
persistant connections. Which should you use?

Mysql_connect opens a new connection each time a PHP page is
called up, and closes the connection down again at the end
of the request. It's ideal for pages that don't have a heavy
usage - doesn't need tuning, is straightforward internally.
If you compare MySQL to a shop, this is the connection that
you would use for a small shop where the door is opened each
time a new customer wishes to enter.

Mysql_pconnect will also open a new connection when a PHP
page is called up (at any rate, it will the first time after
a server reboot), but it will NOT close the connection at
the end of the request - instead, it will save it in a
connection pool so that a subsequent request can continue to
use the same connection. It's intended for pages that do
have a heavy usage - where the resources burn up by opening
and closing connections every time might have a severe
effect on performance. If your local supermarket had a door
that was opened each time someone went in and out, there
would be a lot of needless opening and closing going on -
better to leave it open and let a whole lot of people in and
out at the same time.

But mysql_pconnect does require some tuning of the servers
and you may need to limit the numbers of connections /
children and configure timeouts and how to deal with idle
children. The PHP website includes an overview of this to
get you started.

Finally, it is worth stressing what a persistant connect
does NOT give you. It does NOT give you sessions. It does
NOT give you a per-site-visitor login. It does NOT give you
any extra functioanllity. What it does give you - in the
right circumstances - is an efficiency improvement.

Is This Answer Correct ?    8 Yes 1 No

Post New Answer

More PHP Interview Questions

Whhat is a Functions

1 Answers   IQ,


Is it possible to get the screen resolution and like with php?

1 Answers  


Which function is used to read a single character from a file in PHP.

0 Answers  


For printing out strings, there are echo, print and printf. Explain the differences.

3 Answers  


Can we run php in apache tomcat?

0 Answers  






How can you retrieve data from the mysql database using php?

0 Answers  


How do http requests work?

0 Answers  


Are static variables final?

0 Answers  


I am trying to assign a variable the value of 0123, but it keeps coming up with a different number, what is the problem?

0 Answers  


How do sessions work in php?

0 Answers  


How to Calculate Internal links & External Link in Website.(For Example YAHOO WEBSITE)

1 Answers  


What does the unlink() function mean?

0 Answers  


Categories