Example #1
0
 /**
  * Establishes the class properties for each test
  *
  * Can not use setUp() because we are using a dataProvider to get multiple
  * MDB2 objects per test.
  *
  * @param array $ci  an associative array with two elements.  The "dsn"
  *                   element must contain an array of DSN information.
  *                   The "options" element must be an array of connection
  *                   options.
  */
 protected function manualSetUp($ci)
 {
     $this->db = MDB2::factory($ci['dsn'], $ci['options']);
     if (MDB2::isError($this->db)) {
         $this->markTestSkipped($this->db->getMessage());
     }
     $this->dsn = self::$dsns[$this->db->phptype]['dsn'];
     $this->options = self::$dsns[$this->db->phptype]['options'];
     $this->database = $this->db->getDatabase();
     $this->db->setDatabase($this->database);
     if ($this->database == ':memory:') {
         // Disable messages from other packages while building schema.
         $prior = error_reporting(E_ALL & ~E_STRICT & ~E_DEPRECATED);
         build_schema($this->db);
         error_reporting($prior);
     }
     $this->db->expectError(MDB2_ERROR_UNSUPPORTED);
     $this->clearTables();
 }
Example #2
0
 /**
  * connect to the database using mdb2
  */
 public static function connectMDB2()
 {
     if (self::$connection) {
         if (self::$backend == self::BACKEND_PDO) {
             self::disconnect();
         } else {
             return true;
         }
     }
     // The global data we need
     $name = OC_Config::getValue("dbname", "owncloud");
     $host = OC_Config::getValue("dbhost", "");
     $user = OC_Config::getValue("dbuser", "");
     $pass = OC_Config::getValue("dbpassword", "");
     $type = OC_Config::getValue("dbtype", "sqlite");
     $SERVERROOT = OC::$SERVERROOT;
     $datadir = OC_Config::getValue("datadirectory", "{$SERVERROOT}/data");
     // do nothing if the connection already has been established
     if (!self::$MDB2) {
         // Require MDB2.php (not required in the head of the file so we only load it when needed)
         require_once 'MDB2.php';
         // Prepare options array
         $options = array('portability' => MDB2_PORTABILITY_ALL - MDB2_PORTABILITY_FIX_CASE, 'log_line_break' => '<br>', 'idxname_format' => '%s', 'debug' => true, 'quote_identifier' => true);
         // Add the dsn according to the database type
         switch ($type) {
             case 'sqlite':
             case 'sqlite3':
                 $dsn = array('phptype' => $type, 'database' => "{$datadir}/{$name}.db", 'mode' => '0644');
                 break;
             case 'mysql':
                 $dsn = array('phptype' => 'mysql', 'username' => $user, 'password' => $pass, 'hostspec' => $host, 'database' => $name);
                 break;
             case 'pgsql':
                 $dsn = array('phptype' => 'pgsql', 'username' => $user, 'password' => $pass, 'hostspec' => $host, 'database' => $name);
                 break;
             case 'oci':
                 $dsn = array('phptype' => 'oci8', 'username' => $user, 'password' => $pass, 'charset' => 'AL32UTF8');
                 if ($host != '') {
                     $dsn['hostspec'] = $host;
                     $dsn['database'] = $name;
                 } else {
                     // use dbname for hostspec
                     $dsn['hostspec'] = $name;
                     $dsn['database'] = $user;
                 }
                 break;
             default:
                 return false;
         }
         // Try to establish connection
         self::$MDB2 = MDB2::factory($dsn, $options);
         // Die if we could not connect
         if (PEAR::isError(self::$MDB2)) {
             OC_Log::write('core', self::$MDB2->getUserInfo(), OC_Log::FATAL);
             OC_Log::write('core', self::$MDB2->getMessage(), OC_Log::FATAL);
             OC_Template::printErrorPage('can not connect to database, using ' . $type . '. (' . self::$MDB2->getUserInfo() . ')');
         }
         // We always, really always want associative arrays
         self::$MDB2->setFetchMode(MDB2_FETCHMODE_ASSOC);
     }
     // we are done. great!
     return true;
 }