diff --git a/admin/innodb.php b/admin/innodb.php index 93238106cb1..98e7991e295 100644 --- a/admin/innodb.php +++ b/admin/innodb.php @@ -14,7 +14,7 @@ admin_externalpage_print_header(); print_heading('Convert all MySQL tables from MYISAM to InnoDB'); - if ($CFG->dbfamily != 'mysql') { + if ($DB->get_dbfamily() != 'mysql') { notice('This function is for MySQL databases only!', 'index.php'); } diff --git a/lib/accesslib.php b/lib/accesslib.php index c37780b0a69..a091621e6c0 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -5352,12 +5352,13 @@ function build_context_path($force=false) { * * Different code for each database - mostly for performance reasons */ - if ($CFG->dbfamily == 'mysql') { + $dbfamily = $DB->get_dbfamily(); + if ($dbfamily == 'mysql') { $updatesql = "UPDATE {context} ct, {context_temp} temp SET ct.path = temp.path, ct.depth = temp.depth WHERE ct.id = temp.id"; - } else if ($CFG->dbfamily == 'oracle') { + } else if ($dbfamily == 'oracle') { $updatesql = "UPDATE {context} ct SET (ct.path, ct.depth) = (SELECT temp.path, temp.depth @@ -5366,7 +5367,7 @@ function build_context_path($force=false) { WHERE EXISTS (SELECT 'x' FROM {context_temp} temp WHERE temp.id = ct.id)"; - } else if ($CFG->dbfamily == 'postgres' or $CFG->dbfamily == 'mssql') { + } else if ($dbfamily == 'postgres' or $dbfamily == 'mssql') { $updatesql = "UPDATE {context} SET path = temp.path, depth = temp.depth diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 862e8e5a73d..fd5a0ebf3ac 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -93,7 +93,8 @@ function xmldb_main_upgrade($oldversion) { upgrade_set_timeout(60*20); // this may take a while /// Under MySQL and Postgres... detect old NULL contents and change them by correct empty string. MDL-14859 - if ($CFG->dbfamily == 'mysql' || $CFG->dbfamily == 'postgres') { + $dbfamily = $DB->get_dbfamily(); + if ($dbfamily === 'mysql' || $dbfamily === 'postgres') { $DB->execute("UPDATE {user} SET idnumber = '' WHERE idnumber IS NULL"); } diff --git a/lib/searchlib.php b/lib/searchlib.php index 7343afa9458..ceb462d5f8e 100644 --- a/lib/searchlib.php +++ b/lib/searchlib.php @@ -313,19 +313,19 @@ class search_parser { */ function search_generate_text_SQL($parsetree, $datafield, $metafield, $mainidfield, $useridfield, $userfirstnamefield, $userlastnamefield, $timefield, $instancefield) { - global $CFG; + global $CFG, $DB; static $p = 0; /// First of all, search for reasons to switch to standard SQL generation /// Only mysql are supported for now - if ($CFG->dbfamily != 'mysql') { + if ($DB->get_db_family() != 'mysql') { return search_generate_SQL($parsetree, $datafield, $metafield, $mainidfield, $useridfield, $userfirstnamefield, $userlastnamefield, $timefield, $instancefield); } /// Some languages don't have "word separators" and MySQL FULLTEXT doesn't perform well with them, so /// switch to standard SQL search generation - if ($CFG->dbfamily == 'mysql') { + if ($DB->get_db_family() == 'mysql') { $nonseparatedlangs = array('ja_utf8', 'th_utf8', 'zh_cn_utf8', 'zh_tw_utf8'); if (in_array(current_language(), $nonseparatedlangs)) { return search_generate_SQL($parsetree, $datafield, $metafield, $mainidfield, $useridfield, diff --git a/mod/data/field/latlong/field.class.php b/mod/data/field/latlong/field.class.php index 9985c84d145..87ed62a7d40 100755 --- a/mod/data/field/latlong/field.class.php +++ b/mod/data/field/latlong/field.class.php @@ -193,8 +193,8 @@ class data_field_latlong extends data_field_base { } function get_sort_sql($fieldname) { - global $CFG; - switch ($CFG->dbfamily) { + global $DB; + switch ($DB->get_db_family()) { case 'mysql': // string in an arithmetic operation is converted to a floating-point number return '('.$fieldname.'+0.0)'; diff --git a/mod/data/field/number/field.class.php b/mod/data/field/number/field.class.php index 23835e29a99..1fe18c933f0 100755 --- a/mod/data/field/number/field.class.php +++ b/mod/data/field/number/field.class.php @@ -86,8 +86,8 @@ class data_field_number extends data_field_base { } function get_sort_sql($fieldname) { - global $CFG; - switch ($CFG->dbfamily) { + global $DB; + switch ($DB->get_db_family()) { case 'mysql': // string in an arithmetic operation is converted to a floating-point number return '('.$fieldname.'+0.0)'; diff --git a/mod/forum/search.php b/mod/forum/search.php index 95bf7b2bb64..3d4b6d7ecab 100644 --- a/mod/forum/search.php +++ b/mod/forum/search.php @@ -246,7 +246,7 @@ * @todo Document this function */ function forum_print_big_search_form($course) { - global $CFG, $words, $subject, $phrase, $user, $userid, $fullwords, $notwords, $datefrom, $dateto; + global $CFG, $DB, $words, $subject, $phrase, $user, $userid, $fullwords, $notwords, $datefrom, $dateto; print_simple_box(get_string('searchforumintro', 'forum'), 'center', '', '', 'searchbox', 'intro'); @@ -276,7 +276,7 @@ function forum_print_big_search_form($course) { echo ''; echo ''; - if ($CFG->dbfamily == 'mysql' || $CFG->dbfamily == 'postgres') { + if ($DB->get_db_family() == 'mysql' || $DB->get_db_family() == 'postgres') { echo ''; echo ''; echo ''; diff --git a/mod/wiki/ewikimoodlelib.php b/mod/wiki/ewikimoodlelib.php index 97b3bd8fbdd..af044e53d64 100644 --- a/mod/wiki/ewikimoodlelib.php +++ b/mod/wiki/ewikimoodlelib.php @@ -191,7 +191,7 @@ function ewiki_database_moodle($action, &$args, $sw1, $sw2) { array("flags","meta","lastmodified"); */ case "GETALL": - switch ($CFG->dbfamily) { + switch ($DB->get_db_family()) { case 'postgres': // All but the latest version eliminated by DISTINCT // ON (pagename) diff --git a/search/lib.php b/search/lib.php index b715d2ad53d..6706fc3e78a 100644 --- a/search/lib.php +++ b/search/lib.php @@ -23,7 +23,6 @@ function search_get_document_types($prefix = 'SEARCH_TYPE_') { function search_get_document_types($prefix = 'X_SEARCH_TYPE_') { function search_get_additional_modules() { function search_shorten_url($url, $length=30) { -function search_escape_string($str) { function search_stopwatch($cli = false) { function search_pexit($str = "") { */ @@ -153,27 +152,6 @@ function search_shorten_url($url, $length=30) { return substr($url, 0, $length)."..."; } //search_shorten_url -/** -* a local function for escaping -* @param str the string to escape -* @return the escaped string -*/ -function search_escape_string($str) { - global $CFG; - - switch ($CFG->dbfamily) { - case 'mysql': - $s = mysql_real_escape_string($str); - break; - case 'postgres': - $s = pg_escape_string($str); - break; - default: - $s = addslashes($str); - } - return $s; -} //search_escape_string - /** * simple timer function, on first call, records a current microtime stamp, outputs result on 2nd call * @param cli an output formatting switch