예제 #1
0
 public function testHasConnection()
 {
     //Test on connection name that does not exist
     $this->assertFalse(DinklyDataConfig::hasConnection('monkey_shoes'));
     //Test create connection and then see if exists
     DinklyDataConfig::setActiveConnection($this->db_creds);
     $this->assertTrue(DinklyDataConfig::hasConnection('unit_test'));
 }
 /**
  * Test function to make check for successful DB connection
  *
  * @param string $schema defaults to first found in config
  * @return bool true on successful connection false otherwise
  * @throws Exception if connection failed
  */
 public static function testDB($schema = null)
 {
     try {
         if ($schema) {
             if (DinklyDataConfig::hasConnection($schema)) {
                 DinklyDataConfig::setActiveConnection($schema);
             } else {
                 echo "Connection failed: Schema does not exist\n";
                 return false;
             }
         }
         if (self::fetchDB()) {
             return true;
         }
     } catch (PDOException $e) {
         echo "Connection failed: " . $e->getMessage() . "\n";
         return false;
     }
     return false;
 }