/** * Change default connect to $dbc_name * * @param array $params Params for database connection * @param string $name Database name * @return bool True on success false otherwise */ function db_connect_to($params, $name) { return Database::changeDb($name, $params); }
/** * Connects to database * * @param string $host Database host * @param string $name Database name * @param string $user Database user * @param string $password Database password * @param string $table_prefix Database table prefix * @param string $names Database names for SET NAMES * @return bool Tue on succes connection or already connected, false otherwise */ public function connectToDB($host, $name, $user, $password, $table_prefix, $database_backend, $names = 'utf8') { $connected = true; if ($this->_db_connection == null) { Registry::set('config.table_prefix', $table_prefix); Registry::set('config.database_backend', $database_backend); $connected = Database::connect($user, $password, $host, '', array('table_prefix' => $table_prefix)); if (!$connected) { $this->setNotification('E', '', $this->t('could_not_connect_to_database'), true, 'server_configuration'); } elseif (!Database::changeDb($name)) { // CREATE TABLE SQL command will throw the Fatal error if user does not have the CREATE permissions Registry::set('runtime.database.skip_errors', true); if (!Database::createDb($name)) { $this->setNotification('E', '', $this->t('could_not_create_database'), true, 'server_configuration'); $connected = false; } else { Database::changeDb($name); } Registry::set('runtime.database.skip_errors', false); } if ($connected) { db_query("SET NAMES ?s", $names); db_query("SET sql_mode = ''"); } $this->_db_connection = $connected; } return $connected; }