From 78a713685d48c164c117df0b824495efd30bb0bb Mon Sep 17 00:00:00 2001 From: John Okely Date: Mon, 27 Jul 2015 14:17:45 +0800 Subject: [PATCH] MDL-50307 auth_db: Stop using AS to prevent error with some drivers --- auth/db/auth.php | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/auth/db/auth.php b/auth/db/auth.php index f03cbef44d6..147ef604cb6 100644 --- a/auth/db/auth.php +++ b/auth/db/auth.php @@ -110,7 +110,7 @@ class auth_plugin_db extends auth_plugin_base { $authdb = $this->db_init(); - $rs = $authdb->Execute("SELECT {$this->config->fieldpass} AS userpass + $rs = $authdb->Execute("SELECT {$this->config->fieldpass} FROM {$this->config->table} WHERE {$this->config->fielduser} = '".$this->ext_addslashes($extusername)."'"); if (!$rs) { @@ -125,7 +125,7 @@ class auth_plugin_db extends auth_plugin_base { } $fields = array_change_key_case($rs->fields, CASE_LOWER); - $fromdb = $fields['userpass']; + $fromdb = $fields[strtolower($this->config->fieldpass)]; $rs->Close(); $authdb->Close(); @@ -217,18 +217,21 @@ class auth_plugin_db extends auth_plugin_base { if ($selectfields) { $select = array(); foreach ($selectfields as $localname=>$externalname) { - $select[] = "$externalname AS $localname"; + $select[] = "$externalname"; } $select = implode(', ', $select); $sql = "SELECT $select FROM {$this->config->table} WHERE {$this->config->fielduser} = '".$this->ext_addslashes($extusername)."'"; + if ($rs = $authdb->Execute($sql)) { if (!$rs->EOF) { - $fields_obj = $rs->FetchObj(); - $fields_obj = (object)array_change_key_case((array)$fields_obj , CASE_LOWER); - foreach ($selectfields as $localname=>$externalname) { - $result[$localname] = core_text::convert($fields_obj->{strtolower($localname)}, $this->config->extencoding, 'utf-8'); + $fields = $rs->FetchRow(); + // Convert the associative array to an array of its values so we don't have to worry about the case of its keys. + $fields = array_values($fields); + foreach (array_keys($selectfields) as $index => $localname) { + $value = $fields[$index]; + $result[$localname] = core_text::convert($value, $this->config->extencoding, 'utf-8'); } } $rs->Close(); @@ -487,15 +490,15 @@ class auth_plugin_db extends auth_plugin_base { $authdb = $this->db_init(); // Fetch userlist. - $rs = $authdb->Execute("SELECT {$this->config->fielduser} AS username + $rs = $authdb->Execute("SELECT {$this->config->fielduser} FROM {$this->config->table} "); if (!$rs) { print_error('auth_dbcantconnect','auth_db'); } else if (!$rs->EOF) { while ($rec = $rs->FetchRow()) { - $rec = (object)array_change_key_case((array)$rec , CASE_LOWER); - array_push($result, $rec->username); + $rec = array_change_key_case((array)$rec, CASE_LOWER); + array_push($result, $rec[strtolower($this->config->fielduser)]); } } -- 2.11.4.GIT