protected function validateDatabase($e) { if (!extension_loaded('pdo')) { $e->add($this->getDBErrorMsg()); } else { $db = \Database::getFactory()->createConnection(array('host' => $_POST['DB_SERVER'], 'user' => $_POST['DB_USERNAME'], 'password' => $_POST['DB_PASSWORD'], 'database' => $_POST['DB_DATABASE'])); $DB_SERVER = $_POST['DB_SERVER']; $DB_DATABASE = $_POST['DB_DATABASE']; if ($DB_SERVER && $DB_DATABASE) { if (!$db) { $e->add(t('Unable to connect to database.')); } else { $num = $db->GetCol("show tables"); if (count($num) > 0) { $e->add(t('There are already %s tables in this database. concrete5 must be installed in an empty database.', count($num))); } $support = $db->GetOne('SELECT SUPPORT FROM INFORMATION_SCHEMA.ENGINES WHERE ENGINE = \'InnoDB\''); if (!in_array($support, array('YES', 'DEFAULT'))) { $e->add(t('Your MySQL database does not support InnoDB database tables. These are required.')); } } } } return $e; }
public static function getUserData($key, $value) { // connect to database $db = Database::getFactory()->getConnection(); $sql = "SELECT * FROM users WHERE " . $key . " = :key LIMIT 1"; $query = $db->prepare($sql); $query->execute(array(':key' => $value)); return $query->fetch(); }
public function getConnection() { if (self::$conn === null) { $config = \Config::get('database'); $connection_config = $config['connections'][$config['default-connection']]; $db = Database::getFactory()->createConnection(array('host' => $connection_config['server'], 'user' => $connection_config['username'], 'password' => $connection_config['password'], 'database' => $connection_config['database'])); self::$conn = $this->createDefaultDBConnection($db->getWrappedConnection(), 'test'); $this->db = $db; } return self::$conn; }
public function testValidConnection() { $config = \Config::get('database'); $connection_config = $config['connections'][$config['default-connection']]; $connection = Database::getFactory()->createConnection(array('host' => $connection_config['server'], 'user' => $connection_config['username'], 'password' => $connection_config['password'], 'database' => $connection_config['database'])); try { $errorCode = $connection->errorCode(); $this->assertTrue($errorCode == 0); } catch (PDOException $e) { $this->fail('Unable to connect to the database.'); } }
public static function validateUserName($name) { // check if it fits the alphanumeric pattern and its length (min 3, max 20) if (!filter_var($name, FILTER_VALIDATE_REGEXP, array("options" => array("regexp" => "/^[A-Za-z][a-zA-Z0-9]{3,20}\$/")))) { Session::add('feedback_negative', 'Error. User name can\'t be longer than 20 or shorter than 3 characters. It also can\'t contain any other characters than letters and numbers and it has to start with a letter.'); return false; } // check if the user name is unique $db = Database::getFactory()->getConnection(); $query = $db->prepare("SELECT user_id FROM users WHERE user_name = :user_name LIMIT 1"); $query->execute(array(':user_name' => $name)); if ($query->rowCount() != 0) { Session::add('feedback_negative', 'User name already exists.'); return false; } return true; }
protected function validateDatabase($e) { if (!extension_loaded('pdo')) { $e->add($this->getDBErrorMsg()); } else { $db = \Database::getFactory()->createConnection(array('host' => $_POST['DB_SERVER'], 'user' => $_POST['DB_USERNAME'], 'password' => $_POST['DB_PASSWORD'], 'database' => $_POST['DB_DATABASE'])); $DB_SERVER = $_POST['DB_SERVER']; $DB_DATABASE = $_POST['DB_DATABASE']; if ($DB_SERVER && $DB_DATABASE) { if (!$db) { $e->add(t('Unable to connect to database.')); } else { $num = $db->GetCol("show tables"); if (count($num) > 0) { $e->add(t('There are already %s tables in this database. concrete5 must be installed in an empty database.', count($num))); } try { $support = $db->GetAll('show engines'); $supported = false; foreach ($support as $engine) { $engine = array_change_key_case($engine, CASE_LOWER); if (isset($engine['engine']) && strtolower($engine['engine']) == 'innodb') { $supported = true; } } if (!$supported) { $e->add(t('Your MySQL database does not support InnoDB database tables. These are required.')); } } catch (\Exception $exception) { // we're going to just proceed and hope for the best. } } } } return $e; }
*/ require $corePath . '/bootstrap/configure.php'; /** * ---------------------------------------------------------------------------- * Include all autoloaders * ---------------------------------------------------------------------------- */ require $corePath . '/bootstrap/autoload.php'; /** * ---------------------------------------------------------------------------- * Begin concrete5 startup. * ---------------------------------------------------------------------------- */ $cms = (require $corePath . '/bootstrap/start.php'); \Database::extend('install', function () use($cliconfig) { return \Database::getFactory()->createConnection(array('host' => $cliconfig['db-server'], 'user' => $cliconfig['db-username'], 'password' => $cliconfig['db-password'], 'database' => $cliconfig['db-database'])); }); \Database::setDefaultConnection('install'); $cms['config']['database.connections.install'] = array(); if ($cliconfig['reinstall'] === 'yes') { // Remove all files from the files directory function removeDemoFiles($path) { global $target; $path .= end(str_split($path)) !== '/' ? '/' : ''; foreach (glob($path . "*") as $file) { if (is_dir($file)) { removeDemoFiles($file); } if (is_file($file)) { unlink($file);