Skip to content

Commit

Permalink
Merge pull request #1 from kiddivouchers/add-mysqli-support
Browse files Browse the repository at this point in the history
Add MySQLi support
  • Loading branch information
cs278 authored Feb 18, 2020
2 parents e5022b0 + 11b652b commit a7d7219
Show file tree
Hide file tree
Showing 6 changed files with 536 additions and 9 deletions.
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
root = true

[*]
; Encoding
charset = utf-8
end_of_line = lf

; Indents
indent_style = tab
indent_size = 4

; Whitespace
insert_final_newline = true
trim_trailing_whitespace = true
3 changes: 3 additions & 0 deletions classes/database/mysqli.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php defined('SYSPATH') OR die('No direct script access.');

class Database_MySQLi extends Kohana_Database_MySQLi {}
3 changes: 3 additions & 0 deletions classes/database/mysqli/result.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php defined('SYSPATH') OR die('No direct script access.');

class Database_MySQLi_Result extends Kohana_Database_MySQLi_Result {}
32 changes: 23 additions & 9 deletions classes/kohana/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ public static function instance($name = NULL, array $config = NULL)
$driver = 'Database_'.ucfirst($config['type']);

// Create the database connection instance
new $driver($name, $config);
$driver = new $driver($name, $config);

// Store the database instance
Database::$instances[$name] = $driver;
}

return Database::$instances[$name];
Expand Down Expand Up @@ -117,9 +120,6 @@ protected function __construct($name, array $config)
{
$this->_config['table_prefix'] = '';
}

// Store the database instance
Database::$instances[$name] = $this;
}

/**
Expand Down Expand Up @@ -500,9 +500,13 @@ public function quote($value)
*/
public function quote_column($column)
{
// Identifiers are escaped by repeating them
$escaped_identifier = $this->_identifier.$this->_identifier;

if (is_array($column))
{
list($column, $alias) = $column;
$alias = str_replace($this->_identifier, $escaped_identifier, $alias);
}

if ($column instanceof Database_Query)
Expand All @@ -520,15 +524,12 @@ public function quote_column($column)
// Convert to a string
$column = (string) $column;

$column = str_replace($this->_identifier, $escaped_identifier, $column);

if ($column === '*')
{
return $column;
}
elseif (strpos($column, '"') !== FALSE)
{
// Quote the column in FUNC("column") identifiers
$column = preg_replace('/"(.+?)"/e', '$this->quote_column("$1")', $column);
}
elseif (strpos($column, '.') !== FALSE)
{
$parts = explode('.', $column);
Expand Down Expand Up @@ -584,9 +585,14 @@ public function quote_column($column)
*/
public function quote_table($table)
{

// Identifiers are escaped by repeating them
$escaped_identifier = $this->_identifier.$this->_identifier;

if (is_array($table))
{
list($table, $alias) = $table;
$alias = str_replace($this->_identifier, $escaped_identifier, $alias);
}

if ($table instanceof Database_Query)
Expand All @@ -604,6 +610,8 @@ public function quote_table($table)
// Convert to a string
$table = (string) $table;

$table = str_replace($this->_identifier, $escaped_identifier, $table);

if (strpos($table, '.') !== FALSE)
{
$parts = explode('.', $table);
Expand Down Expand Up @@ -654,9 +662,13 @@ public function quote_table($table)
*/
public function quote_identifier($value)
{
// Identifiers are escaped by repeating them
$escaped_identifier = $this->_identifier.$this->_identifier;

if (is_array($value))
{
list($value, $alias) = $value;
$alias = str_replace($this->_identifier, $escaped_identifier, $alias);
}

if ($value instanceof Database_Query)
Expand All @@ -674,6 +686,8 @@ public function quote_identifier($value)
// Convert to a string
$value = (string) $value;

$value = str_replace($this->_identifier, $escaped_identifier, $value);

if (strpos($value, '.') !== FALSE)
{
$parts = explode('.', $value);
Expand Down
Loading

0 comments on commit a7d7219

Please sign in to comment.