From 93901eb42feb1b56e9e8e8ec2cbd7c45b55bb096 Mon Sep 17 00:00:00 2001 From: stronk7 Date: Thu, 11 Jan 2007 20:08:00 +0000 Subject: [PATCH] Change some connections to non-persistent and force new connections to avoid mysql (and oracle, I think) reuse of the main one. MDL-8152 --- auth/db/auth.php | 37 +++++++++++++------------------------ enrol/database/enrol.php | 27 ++------------------------- 2 files changed, 15 insertions(+), 49 deletions(-) diff --git a/auth/db/auth.php b/auth/db/auth.php index 2d7065a11d..0025d0d917 100644 --- a/auth/db/auth.php +++ b/auth/db/auth.php @@ -44,21 +44,9 @@ class auth_plugin_db { global $CFG; - // This is a hack to workaround what seems to be a bug in ADOdb with accessing - // two databases of the same kind ... it seems to get confused when trying to access - // the first database again, after having accessed the second. - // The following hack will make the database explicit which keeps it happy - // This seems to broke postgesql so .. - - $prefix = $CFG->prefix.''; // Remember it. The '' is to prevent PHP5 reference.. see bug 3223 - - if ($CFG->dbtype != 'postgres7') { - $CFG->prefix = $CFG->dbname.$CFG->prefix; - } - - // Connect to the external database + // Connect to the external database (forcing new connection) $authdb = &ADONewConnection($this->config->type); - $authdb->PConnect($this->config->host, $this->config->user, $this->config->pass, $this->config->name); + $authdb->Connect($this->config->host, $this->config->user, $this->config->pass, $this->config->name, true); $authdb->SetFetchMode(ADODB_FETCH_ASSOC); if ($this->config->passtype === 'internal') { @@ -97,8 +85,6 @@ class auth_plugin_db { AND {$this->config->fieldpass} = '$password' "); $authdb->Close(); - $CFG->prefix = $prefix; - if (!$rs) { print_error('auth_dbcantconnect','auth'); return false; @@ -122,9 +108,9 @@ class auth_plugin_db { global $CFG; - ADOLoadCode($this->config->type); - $authdb = &ADONewConnection(); - $authdb->PConnect($this->config->host, $this->config->user, $this->config->pass, $this->config->name); + // Connect to the external database (forcing new connection) + $authdb = &ADONewConnection($this->config->type); + $authdb->Connect($this->config->host, $this->config->user, $this->config->pass, $this->config->name, true); $authdb->SetFetchMode(ADODB_FETCH_ASSOC); $fields = array("firstname", "lastname", "email", "phone1", "phone2", @@ -341,8 +327,10 @@ class auth_plugin_db { } function user_exists ($username) { - $authdb = &ADONewConnection($this->config->type); - $authdb->PConnect($this->config->host, $this->config->user, $this->config->pass, $this->config->name); + + // Connect to the external database (forcing new connection) + $authdb = &ADONewConnection($this->config->type); + $authdb->Connect($this->config->host, $this->config->user, $this->config->pass, $this->config->name, true); $authdb->SetFetchMode(ADODB_FETCH_ASSOC); $rs = $authdb->Execute("SELECT * FROM {$this->config->table} @@ -370,9 +358,10 @@ class auth_plugin_db { function get_userlist() { - // Connect to the external database - $authdb = &ADONewConnection($this->config->type); - $authdb->PConnect($this->config->host,$this->config->user,$this->config->pass,$this->config->name); + + // Connect to the external database (forcing new connection) + $authdb = &ADONewConnection($this->config->type); + $authdb->Connect($this->config->host, $this->config->user, $this->config->pass, $this->config->name, true); $authdb->SetFetchMode(ADODB_FETCH_ASSOC); // fetch userlist diff --git a/enrol/database/enrol.php b/enrol/database/enrol.php index d97462871c..6021490a6f 100644 --- a/enrol/database/enrol.php +++ b/enrol/database/enrol.php @@ -590,28 +590,12 @@ function create_course ($course,$skip_fix_course_sortorder=0){ function enrol_connect() { global $CFG; - // This is a hack to workaround what seems to be a bug in ADOdb with accessing - // two MySQL databases ... it seems to get confused when trying to access - // the first database again, after having accessed the second. - // The following hack will make the database explicit which keeps it happy - if ($CFG->dbtype === 'mysql' && $CFG->enrol_dbtype === 'mysql') { - if (strpos($CFG->prefix, $CFG->dbname) === false) { - $CFG->prefix_old = $CFG->prefix; - $CFG->prefix = "`$CFG->dbname`.$CFG->prefix"; - } - } - - // Try to connect to the external database + // Try to connect to the external database (forcing new connection) $enroldb = &ADONewConnection($CFG->enrol_dbtype); - if ($enroldb->PConnect($CFG->enrol_dbhost,$CFG->enrol_dbuser,$CFG->enrol_dbpass,$CFG->enrol_dbname)) { + if ($enroldb->Connect($CFG->enrol_dbhost, $CFG->enrol_dbuser, $CFG->enrol_dbpass, $CFG->enrol_dbname, true)) { $enroldb->SetFetchMode(ADODB_FETCH_ASSOC); ///Set Assoc mode always after DB connection return $enroldb; } else { - // do a bit of cleanup, and lot the problem - if (!empty($CFG->prefix_old)) { - $CFG->prefix =$CFG->prefix_old; // Restore it just in case - unset($CFG->prefix_old); - } trigger_error("Error connecting to enrolment DB backend with: " . "$CFG->enrol_dbhost,$CFG->enrol_dbuser,$CFG->enrol_dbpass,$CFG->enrol_dbname"); return false; @@ -623,13 +607,6 @@ function enrol_disconnect($enroldb) { global $CFG; $enroldb->Close(); - - // Cleanup the mysql - // hack - if (!empty($CFG->prefix_old)) { - $CFG->prefix =$CFG->prefix_old; // Restore it just in case - unset($CFG->prefix_old); - } } /** -- 2.39.5