]> git.mjollnir.org Git - moodle.git/commitdiff
Change some connections to non-persistent and force new connections
authorstronk7 <stronk7>
Thu, 11 Jan 2007 20:08:00 +0000 (20:08 +0000)
committerstronk7 <stronk7>
Thu, 11 Jan 2007 20:08:00 +0000 (20:08 +0000)
to avoid mysql (and oracle, I think) reuse of the main one. MDL-8152

auth/db/auth.php
enrol/database/enrol.php

index 2d7065a11dcb7212035f5eaf48ce640e72c2b19b..0025d0d91764d6b52fdaed2bbc6423a40031d261 100644 (file)
@@ -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
index d97462871c62fe3667aac12308d7b4ff2bb0cc69..6021490a6f4b2eaf1662031874de6ed78500691f 100644 (file)
@@ -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);
-    }
 }
 
 /**