original_string: protected function init() {
          if (isset($this->extdb)) {
              return !empty($this->extdb);
          }
  
          $dbdriver = $this->get_config('dbdriver');
          if (empty($dbdriver)) {
              $this->extdb = false;
              return false;
          }
          list($dblibrary, $dbtype) = explode('/', $dbdriver);
  
          if (!$db = \moodle_database::get_driver_instance($dbtype, $dblibrary, true)) {
              debugging("Unknown driver $dblibrary/$dbtype", DEBUG_DEVELOPER);
              $this->extdb = false;
              return false;
          }
  
          $dboptions = array();
          $dboptions['dbpersist'] = $this->get_config('dbpersist', '0');
          $dboptions['dbsocket'] = $this->get_config('dbsocket', '');
          $dboptions['dbport'] = $this->get_config('dbport', '');
          $dboptions['dbschema'] = $this->get_config('dbschema', '');
          $dboptions['dbcollation'] = $this->get_config('dbcollation', '');
          $dboptions['dbhandlesoptions'] = $this->get_config('dbhandlesoptions', false);
          try {
              $db->connect($this->get_config('dbhost'), $this->get_config('dbuser'), $this->get_config('dbpass'),
                  $this->get_config('dbname'), false, $dboptions);
              $tables = $db->get_tables();
              if (!in_array($this->get_config('dbtable'), $tables)) {
                  debugging('Cannot find the specified table', DEBUG_DEVELOPER);
                  $this->extdb = false;
                  return false;
              }
          } catch (\moodle_exception $e) {
              debugging('Cannot connect to external database: ' . $e->getMessage(), DEBUG_DEVELOPER);
              $this->extdb = false;
              return false;
          }
  
          $this->extdb = $db;
          return true;
      }
code: protected function init() {
          if (isset($this->extdb)) {
              return !empty($this->extdb);
          }
  
          $dbdriver = $this->get_config('dbdriver');
          if (empty($dbdriver)) {
              $this->extdb = false;
              return false;
          }
          list($dblibrary, $dbtype) = explode('/', $dbdriver);
  
          if (!$db = \moodle_database::get_driver_instance($dbtype, $dblibrary, true)) {
              debugging("Unknown driver $dblibrary/$dbtype", DEBUG_DEVELOPER);
              $this->extdb = false;
              return false;
          }
  
          $dboptions = array();
          $dboptions['dbpersist'] = $this->get_config('dbpersist', '0');
          $dboptions['dbsocket'] = $this->get_config('dbsocket', '');
          $dboptions['dbport'] = $this->get_config('dbport', '');
          $dboptions['dbschema'] = $this->get_config('dbschema', '');
          $dboptions['dbcollation'] = $this->get_config('dbcollation', '');
          $dboptions['dbhandlesoptions'] = $this->get_config('dbhandlesoptions', false);
          try {
              $db->connect($this->get_config('dbhost'), $this->get_config('dbuser'), $this->get_config('dbpass'),
                  $this->get_config('dbname'), false, $dboptions);
              $tables = $db->get_tables();
              if (!in_array($this->get_config('dbtable'), $tables)) {
                  debugging('Cannot find the specified table', DEBUG_DEVELOPER);
                  $this->extdb = false;
                  return false;
              }
          } catch (\moodle_exception $e) {
              debugging('Cannot connect to external database: ' . $e->getMessage(), DEBUG_DEVELOPER);
              $this->extdb = false;
              return false;
          }
  
          $this->extdb = $db;
          return true;
      }
code_tokens: protected function init ( ) { if ( isset ( $ this -> extdb ) ) { return ! empty ( $ this -> extdb ) ; } $ dbdriver = $ this -> get_config ( 'dbdriver' ) ; if ( empty ( $ dbdriver ) ) { $ this -> extdb = false ; return false ; } list ( $ dblibrary , $ dbtype ) = explode ( '/' , $ dbdriver ) ; if ( ! $ db = \ moodle_database :: get_driver_instance ( $ dbtype , $ dblibrary , true ) ) { debugging ( "Unknown driver $dblibrary/$dbtype" , DEBUG_DEVELOPER ) ; $ this -> extdb = false ; return false ; } $ dboptions = array ( ) ; $ dboptions [ 'dbpersist' ] = $ this -> get_config ( 'dbpersist' , '0' ) ; $ dboptions [ 'dbsocket' ] = $ this -> get_config ( 'dbsocket' , '' ) ; $ dboptions [ 'dbport' ] = $ this -> get_config ( 'dbport' , '' ) ; $ dboptions [ 'dbschema' ] = $ this -> get_config ( 'dbschema' , '' ) ; $ dboptions [ 'dbcollation' ] = $ this -> get_config ( 'dbcollation' , '' ) ; $ dboptions [ 'dbhandlesoptions' ] = $ this -> get_config ( 'dbhandlesoptions' , false ) ; try { $ db -> connect ( $ this -> get_config ( 'dbhost' ) , $ this -> get_config ( 'dbuser' ) , $ this -> get_config ( 'dbpass' ) , $ this -> get_config ( 'dbname' ) , false , $ dboptions ) ; $ tables = $ db -> get_tables ( ) ; if ( ! in_array ( $ this -> get_config ( 'dbtable' ) , $ tables ) ) { debugging ( 'Cannot find the specified table' , DEBUG_DEVELOPER ) ; $ this -> extdb = false ; return false ; } } catch ( \ moodle_exception $ e ) { debugging ( 'Cannot connect to external database: ' . $ e -> getMessage ( ) , DEBUG_DEVELOPER ) ; $ this -> extdb = false ; return false ; } $ this -> extdb = $ db ; return true ; }
docstring: Setup the Database.
  
  @return bool
docstring_tokens: Setup the Database .