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

Cannot use external postgres database without table prefix

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • 2.1.1
    • 2.1, 2.2
    • Libraries
    • PostgreSQL
    • MOODLE_21_STABLE, MOODLE_22_STABLE
    • MOODLE_21_STABLE
    • Hide

      calling the following code snippet currently throws an error:


      <?php

      define('CLI_SCRIPT', true);

      require('config.php');

      $authdb = moodle_database::get_driver_instance('pgsql', 'native');

      $authdb->connect('localhost', 'moodle', 'moodle', 'example_external_database', false);


      Expected result: It works!
      Actual result:


      www-data@moodle:/home/nicols/git/software/moodle$ php example.php
      Default exception handler: <p>Error: database table prefix cannot be empty (postgres)</p>
      <p>The site administrator must fix this problem.</p> Debug:

      • line 125 of /lib/dml/pgsql_native_moodle_database.php: dml_exception thrown
      • line 9 of /example.php: call to pgsql_native_moodle_database->connect()

      !!! <p>Error: database table prefix cannot be empty (postgres)</p>
      <p>The site administrator must fix this problem.</p> !!!
      !! Stack trace: * line 125 of /lib/dml/pgsql_native_moodle_database.php: dml_exception thrown

      • line 9 of /example.php: call to pgsql_native_moodle_database->connect()
        !!
      Show
      calling the following code snippet currently throws an error: <?php define('CLI_SCRIPT', true); require('config.php'); $authdb = moodle_database::get_driver_instance('pgsql', 'native'); $authdb->connect('localhost', 'moodle', 'moodle', 'example_external_database', false); Expected result: It works! Actual result: www-data@moodle:/home/nicols/git/software/moodle$ php example.php Default exception handler: <p>Error: database table prefix cannot be empty (postgres)</p> <p>The site administrator must fix this problem.</p> Debug: line 125 of /lib/dml/pgsql_native_moodle_database.php: dml_exception thrown line 9 of /example.php: call to pgsql_native_moodle_database->connect() !!! <p>Error: database table prefix cannot be empty (postgres)</p> <p>The site administrator must fix this problem.</p> !!! !! Stack trace: * line 125 of /lib/dml/pgsql_native_moodle_database.php: dml_exception thrown line 9 of /example.php: call to pgsql_native_moodle_database->connect() !!

      To create a handle to an external postgres database, you must call

      $foo = moodle_database::get_driver_instance('pgsql', 'native')

      This in turn determines the relevant class, and returns a new instance of that class.

      Moodle requires that you define a table prefix if you're using postgres for the Moodle database, but the postgres driver drops this requirement if $this->external is true.

      The only way of setting the external flag is through the constructor, but since the instance is instantiated via the get_driver_instance, this is not possible.

            poltawski Dan Poltawski
            dobedobedoh Andrew Lyons
            Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
            Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.