Added the ability to use persistent connections

This commit is contained in:
Dmitry Simushev 2011-11-08 16:42:41 +00:00 committed by Dmitriy Simushev
parent 11fa45cb19
commit b54cd674e6
2 changed files with 12 additions and 4 deletions

View File

@ -344,12 +344,18 @@ function getgetparam($name, $default = '')
function connect() function connect()
{ {
global $mysqlhost, $mysqllogin, $mysqlpass, $mysqldb, $dbencoding, $force_charset_in_connection; global $mysqlhost, $mysqllogin, $mysqlpass, $mysqldb, $dbencoding, $force_charset_in_connection, $use_persistent_connection;
if (!extension_loaded("mysql")) { if (!extension_loaded("mysql")) {
die('Mysql extension is not loaded'); die('Mysql extension is not loaded');
} }
$link = @mysql_connect($mysqlhost, $mysqllogin, $mysqlpass) if ($use_persistent_connection) {
or die('Could not connect: ' . mysql_error()); $link = @mysql_pconnect($mysqlhost, $mysqllogin, $mysqlpass);
}else{
$link = @mysql_connect($mysqlhost, $mysqllogin, $mysqlpass);
}
if (! $link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db($mysqldb, $link) or die('Could not select database'); mysql_select_db($mysqldb, $link) or die('Could not select database');
if ($force_charset_in_connection) { if ($force_charset_in_connection) {
mysql_query("SET NAMES '$dbencoding'", $link); mysql_query("SET NAMES '$dbencoding'", $link);

View File

@ -41,6 +41,8 @@ $mysqlprefix = "";
$dbencoding = "utf8"; $dbencoding = "utf8";
$force_charset_in_connection = true; $force_charset_in_connection = true;
$use_persistent_connection = false;
/* /*
* Mailbox * Mailbox
*/ */