Question:
php and mysql?
anonymous
2008-04-08 04:25:38 UTC
when i connect to mysql using php,and then without closin the connection,if i go to a new page thru a link from this page,will i able to retain the connection?
Please reply soon.
Three answers:
jtaber79
2008-04-08 05:19:07 UTC
You could establish a persistent connection using



mysql_pconnect() rather than mysql_connect()



mysql_pconnect() acts very much like mysql_connect() with two major differences.



First, when connecting, the function would first try to find a (persistent) link 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 mysql server will not be closed when the execution of the script ends. Instead, the link will remain open for future use (mysql_close() will not close links established by mysql_pconnect()).



Normally you do NOT want to use mysql_pconnect. This function is designed for environments which have a high overhead to connecting to the database. In a typical MySQL / Apache / PHP environment, Apache will create many child processes which lie in idle waiting for a web request to be assigned to them. Each of these child processes will open and hold its own MySQL connection. So if you have a MySQL server which has a limit of 50 connections, but Apache keeps more than 50 child processes running, each of these child processes can hold a connection to your MySQL server, even while they are idle (idle httpd child processes don't lend their MySQL connection to other httpd children, they hold their own). So even if you only have a few pages which actually connect to MySQL on a busy site, you can run out of connections, with all of them not actually being used.



In general, use mysql_connect() for connecting to MySQL unless that connection takes a long time to establish.
Prav
2008-04-08 04:33:54 UTC
I am not sure about PHP or how it works, but when you go from one page to another, the connection has to be reopened in MySql. Or you can make a connection/ set the conection in one page and then u can set it to a session and call it on each page, that'd be a good pgmming practice.
?
2016-11-06 11:22:13 UTC
you're unlikely to get severe high quality and all of the constructive properties you elect for unfastened. only ain't going to take place. possibly there would desire to be some internet site that helps non-commercial sites like yours, yet they are going to be demanding to discover. the area has to assist the container, the working device, the information superhighway server app (Apache, maximum in all hazard), plus very own homestead page and Perl a minimum of, plus the database. Plus you elect force area and ftp get entry to? stable success.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...