From 9b6663f87a7e679ffba691cf516191fc840cf978 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 24 Nov 2009 19:20:36 -0800 Subject: Update to Kohana r4684 which is now Kohana 2.4 and has substantial changes. --- system/libraries/Database_Mysqli.php | 92 ++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 system/libraries/Database_Mysqli.php (limited to 'system/libraries/Database_Mysqli.php') diff --git a/system/libraries/Database_Mysqli.php b/system/libraries/Database_Mysqli.php new file mode 100644 index 00000000..523fcb19 --- /dev/null +++ b/system/libraries/Database_Mysqli.php @@ -0,0 +1,92 @@ +connection)) + return; + + extract($this->config['connection']); + + // Persistent connections are supported as of PHP 5.3 + if (RUNS_MYSQLND AND $this->config['persistent'] === TRUE) + { + $host = 'p:'.$host; + } + + $host = isset($host) ? $host : $socket; + + if($this->connection = new mysqli($host, $user, $pass, $database, $port)) { + + if (isset($this->config['character_set'])) + { + // Set the character set + $this->set_charset($this->config['character_set']); + } + + // Clear password after successful connect + $this->db_config['connection']['pass'] = NULL; + + return $this->connection; + } + + // Unable to connect to the database + throw new Database_Exception('#:errno: :error', + array(':error' => $this->connection->connect_error, + ':errno' => $this->connection->connect_errno)); + } + + public function disconnect() + { + return is_object($this->connection) and $this->connection->close(); + } + + public function set_charset($charset) + { + // Make sure the database is connected + is_object($this->connection) or $this->connect(); + + if ( ! $this->connection->set_charset($charset)) + { + // Unable to set charset + throw new Database_Exception('#:errno: :error', + array(':error' => $this->connection->connect_error, + ':errno' => $this->connection->connect_errno)); + } + } + + public function query_execute($sql) + { + // Make sure the database is connected + is_object($this->connection) or $this->connect(); + + $result = $this->connection->query($sql); + + // Set the last query + $this->last_query = $sql; + + return new Database_Mysqli_Result($result, $sql, $this->connection, $this->config['object']); + } + + public function escape($value) + { + // Make sure the database is connected + is_object($this->connection) or $this->connect(); + + return $this->connection->real_escape_string($value); + } + +} // End Database_MySQLi -- cgit v1.2.3