public function connect() { if ($this->connection) { return; } if (Database_Mysql::$set_names === NULL) { // Determine if we can use mysql_set_charset(), which is only // available on PHP 5.2.3+ when compiled against MySQL 5.0+ Database_Mysql::$set_names = !function_exists('mysql_set_charset'); } extract($this->config['connection']); $host = isset($host) ? $host : $socket; $port = isset($port) ? ':' . $port : ''; try { // Connect to the database $this->connection = $this->config['persistent'] === TRUE ? mysql_pconnect($host . $port, $user, $pass, $params) : mysql_connect($host . $port, $user, $pass, TRUE, $params); } catch (Kohana_PHP_Exception $e) { // No connection exists $this->connection = NULL; // Unable to connect to the database throw new Database_Exception('#:errno: :error', array(':error' => mysql_error(), ':errno' => mysql_errno())); } if (!mysql_select_db($database, $this->connection)) { // Unable to select database throw new Database_Exception('#:errno: :error', array(':error' => mysql_error($this->connection), ':errno' => mysql_errno($this->connection))); } if (isset($this->config['character_set'])) { // Set the character set $this->set_charset($this->config['character_set']); } }