Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-43884

$DB->get_tables() returns empty array for external databases.

    XMLWordPrintable

Details

    • MOODLE_26_STABLE
    • MOODLE_25_STABLE, MOODLE_26_STABLE
    • MDL-43884-master
    • Hide
      1. This needs to be tested on all databases including both native/freetds MSSQL (your Moodle can be on any single DB, but all supported DBs should be tested using the script below)
      2. Create a script with code below and put it in your Moodle root:-

        <?php
        require_once('config.php');
        $dbtype = 'mysqli';
        $dblibrary = 'native';
        $targetdb = moodle_database::get_driver_instance($dbtype, $dblibrary, true);
        $targetdb->connect($data->dbhost, $data->dbuser, $data->dbpass, $data->dbname, false, $dboptions);
        $tables = $targetdb->get_tables();
        print_object($tables);
        

        (Replace all database properties with the details of the DB you are connecting to)

      3. Make sure you get a proper list printed of tables in your DB printed and not an empty array.
      Show
      This needs to be tested on all databases including both native/freetds MSSQL (your Moodle can be on any single DB, but all supported DBs should be tested using the script below) Create a script with code below and put it in your Moodle root:- <?php require_once('config.php'); $dbtype = 'mysqli'; $dblibrary = 'native'; $targetdb = moodle_database::get_driver_instance($dbtype, $dblibrary, true); $targetdb->connect($data->dbhost, $data->dbuser, $data->dbpass, $data->dbname, false, $dboptions); $tables = $targetdb->get_tables(); print_object($tables); (Replace all database properties with the details of the DB you are connecting to) Make sure you get a proper list printed of tables in your DB printed and not an empty array.
    • 5
    • BACKEND Sprint 10

    Description

      For external databases we pass $db->prefix as false while connecting, where as in get_tables() we have the following check:-

      if ($this->prefix !== '')
      

      This results in empty result as the above condition is never met and the driver considers $prefix to be a valid prefix.

      I have noticed this in PGSQL, but this could be a bug with other drivers too.

      Attachments

        Issue Links

          Activity

            People

              ankit_frenz Ankit Agarwal
              ankit_frenz Ankit Agarwal
              Sam Hemelryk Sam Hemelryk
              Michael de Raadt Michael de Raadt
              David Woloszyn, Huong Nguyen, Jake Dallimore, Meirza, Michael Hawkins, Raquel Ortega, Safat Shahin, Stevani Andolo
              Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                10/Mar/14