Exemplo n.º 1
0
 public function validateConnection($dbDetails)
 {
     ini_set('display_errors', 'off');
     $keys = array("host", "username", "password", "db");
     foreach ($keys as &$key) {
         if (!isset($dbDetails[$key])) {
             throw new LudoDBConnectionException("key " . $key . " is missing.");
         }
         $key = preg_replace("/[^a-z0-9_-]/si", "", $key);
     }
     $this->setConnectionDetails($dbDetails);
     try {
         LudoDB::getInstance();
     } catch (LudoDBException $e) {
         LudoDB::setDb("");
         LudoDB::getInstance()->connect();
         LudoDB::createDatabase($dbDetails['db']);
         $this->setConnectionSuccessMessage('Connection successful. Database ' . $dbDetails['db'] . " created");
     }
     return $dbDetails;
 }