Quick Fix for Multiple Connections
Many of you are aware that using pconnect is, in general, a very bad idea. This is because it is fundamentally broken and can hold on to connections forever, leading to errors on the server.
However, if you want to use subqueries, you need to have multiple connections to your database.
If you only connect to one database, there is a quick-fix solution/hack you can apply by editing the driver file for your database type.
BE AWARE: IF YOU CONNECT TO MORE THAN ONE DATABASE, THIS WILL NOT WORK!
Say, for example, your database is PostgreSQL. You would need to edit the system/database/postgre/postgre_driver.php file, and replace the db_connect function with this code:
static $_pg_connection_id = NULL;
function db_connect()
{
// HACK TO ONLY HAVE ONE CONNECTION PER REQUEST
if(is_null(CI_DB_postgre_driver::$_pg_connection_id)) {
CI_DB_postgre_driver::$_pg_connection_id = @pg_connect($this->_connect_string());
}
return CI_DB_postgre_driver::$_pg_connection_id;
}
This will create a single, shared connection for the entire request. This can reduce overhead, prevent errors, and ensure that transactions are global while they are in use.
Here’s the replacement for MySQL:
static $_my_connection_id = NULL;
function db_connect()
{
if(is_null(CI_DB_mysql_driver::$_my_connection_id))
{
if ($this->port != '')
{
$this->hostname .= ':'.$this->port;
}
CI_DB_mysql_driver::$_my_connection_id = @mysql_connect($this->hostname, $this->username, $this->password, TRUE);
}
return CI_DB_mysql_driver::$_my_connection_id;
}
You can probably get the idea for other DBs. Down the road, I will fix this within DMZ itself.
———————-
Also, DMZ 1.7.0 is on hold temporarily. I’ve got different task that needs some work, but I’ll be releasing it as soon as I finish this current project. I currently don’t have any more changes planned, so if you want to use 1.7.0-RC2, the only differences should be the version number and some minor tweaks to the manual, so you won’t actually have to upgrade.