mirror of
https://github.com/moodle/moodle.git
synced 2025-04-14 04:52:36 +02:00
Change some connections to non-persistent and force new connections
to avoid mysql (and oracle, I think) reuse of the main one. MDL-8152
This commit is contained in:
parent
26de8d35ce
commit
93901eb42f
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user