@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | // Make everything relative to the root |
| 14 | 14 | chdir(dirname(__DIR__)); |
| 15 | 15 | // Setup autoloading |
| 16 | - require_once( __DIR__ . '/vendor/autoload.php' ); |
|
| 16 | + require_once(__DIR__.'/vendor/autoload.php'); |
|
| 17 | 17 | } |
| 18 | 18 | /** |
| 19 | 19 | * Carga Archivo de Configuración |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | static public function getConfig() |
| 23 | 23 | { |
| 24 | - if(file_exists(__DIR__.'/config/local.php')){ |
|
| 24 | + if (file_exists(__DIR__.'/config/local.php')) { |
|
| 25 | 25 | return include __DIR__.'/config/local.php'; |
| 26 | 26 | } |
| 27 | 27 | return include __DIR__.'/config/production.php'; |
@@ -12,26 +12,26 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class Bootstrap |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * <p>Comando para levantar el autoloader</p> |
|
| 17 | - */ |
|
| 18 | - static public function go() |
|
| 19 | - { |
|
| 20 | - // Make everything relative to the root |
|
| 21 | - chdir(dirname(__DIR__)); |
|
| 22 | - // Setup autoloading |
|
| 23 | - require_once( __DIR__ . '/vendor/autoload.php' ); |
|
| 24 | - } |
|
| 25 | - /** |
|
| 26 | - * Carga Archivo de Configuración |
|
| 27 | - * en la seccion de Pruebas. |
|
| 28 | - */ |
|
| 29 | - static public function getConfig() |
|
| 30 | - { |
|
| 31 | - if(file_exists(__DIR__.'/config/local.php')){ |
|
| 32 | - return include __DIR__.'/config/local.php'; |
|
| 33 | - } |
|
| 34 | - return include __DIR__.'/config/production.php'; |
|
| 35 | - } |
|
| 15 | + /** |
|
| 16 | + * <p>Comando para levantar el autoloader</p> |
|
| 17 | + */ |
|
| 18 | + static public function go() |
|
| 19 | + { |
|
| 20 | + // Make everything relative to the root |
|
| 21 | + chdir(dirname(__DIR__)); |
|
| 22 | + // Setup autoloading |
|
| 23 | + require_once( __DIR__ . '/vendor/autoload.php' ); |
|
| 24 | + } |
|
| 25 | + /** |
|
| 26 | + * Carga Archivo de Configuración |
|
| 27 | + * en la seccion de Pruebas. |
|
| 28 | + */ |
|
| 29 | + static public function getConfig() |
|
| 30 | + { |
|
| 31 | + if(file_exists(__DIR__.'/config/local.php')){ |
|
| 32 | + return include __DIR__.'/config/local.php'; |
|
| 33 | + } |
|
| 34 | + return include __DIR__.'/config/production.php'; |
|
| 35 | + } |
|
| 36 | 36 | } |
| 37 | 37 | Bootstrap::go(); |
| 38 | 38 | \ No newline at end of file |
@@ -69,28 +69,28 @@ |
||
| 69 | 69 | * |
| 70 | 70 | * @var array[] |
| 71 | 71 | */ |
| 72 | - public $result_array = array(); |
|
| 72 | + public $result_array = array(); |
|
| 73 | 73 | |
| 74 | 74 | /** |
| 75 | 75 | * Result Object |
| 76 | 76 | * |
| 77 | 77 | * @var object[] |
| 78 | 78 | */ |
| 79 | - public $result_object = array(); |
|
| 79 | + public $result_object = array(); |
|
| 80 | 80 | |
| 81 | 81 | /** |
| 82 | 82 | * Custom Result Object |
| 83 | 83 | * |
| 84 | 84 | * @var object[] |
| 85 | 85 | */ |
| 86 | - public $custom_result_object = array(); |
|
| 86 | + public $custom_result_object = array(); |
|
| 87 | 87 | |
| 88 | 88 | /** |
| 89 | 89 | * Current Row index |
| 90 | 90 | * |
| 91 | 91 | * @var int |
| 92 | 92 | */ |
| 93 | - public $current_row = 0; |
|
| 93 | + public $current_row = 0; |
|
| 94 | 94 | |
| 95 | 95 | /** |
| 96 | 96 | * Number of rows |
@@ -132,12 +132,10 @@ discard block |
||
| 132 | 132 | if (is_int($this->num_rows)) |
| 133 | 133 | { |
| 134 | 134 | return $this->num_rows; |
| 135 | - } |
|
| 136 | - elseif (count($this->result_array) > 0) |
|
| 135 | + } elseif (count($this->result_array) > 0) |
|
| 137 | 136 | { |
| 138 | 137 | return $this->num_rows = count($this->result_array); |
| 139 | - } |
|
| 140 | - elseif (count($this->result_object) > 0) |
|
| 138 | + } elseif (count($this->result_object) > 0) |
|
| 141 | 139 | { |
| 142 | 140 | return $this->num_rows = count($this->result_object); |
| 143 | 141 | } |
@@ -158,12 +156,10 @@ discard block |
||
| 158 | 156 | if ($type === 'array') |
| 159 | 157 | { |
| 160 | 158 | return $this->result_array(); |
| 161 | - } |
|
| 162 | - elseif ($type === 'object') |
|
| 159 | + } elseif ($type === 'object') |
|
| 163 | 160 | { |
| 164 | 161 | return $this->result_object(); |
| 165 | - } |
|
| 166 | - else |
|
| 162 | + } else |
|
| 167 | 163 | { |
| 168 | 164 | return $this->custom_result_object($type); |
| 169 | 165 | } |
@@ -182,8 +178,7 @@ discard block |
||
| 182 | 178 | if (isset($this->custom_result_object[$class_name])) |
| 183 | 179 | { |
| 184 | 180 | return $this->custom_result_object[$class_name]; |
| 185 | - } |
|
| 186 | - elseif ( ! $this->result_id OR $this->num_rows === 0) |
|
| 181 | + } elseif ( ! $this->result_id OR $this->num_rows === 0) |
|
| 187 | 182 | { |
| 188 | 183 | return array(); |
| 189 | 184 | } |
@@ -193,8 +188,7 @@ discard block |
||
| 193 | 188 | if (($c = count($this->result_array)) > 0) |
| 194 | 189 | { |
| 195 | 190 | $_data = 'result_array'; |
| 196 | - } |
|
| 197 | - elseif (($c = count($this->result_object)) > 0) |
|
| 191 | + } elseif (($c = count($this->result_object)) > 0) |
|
| 198 | 192 | { |
| 199 | 193 | $_data = 'result_object'; |
| 200 | 194 | } |
@@ -334,9 +328,13 @@ discard block |
||
| 334 | 328 | return $this->row_data[$n]; |
| 335 | 329 | } |
| 336 | 330 | |
| 337 | - if ($type === 'object') return $this->row_object($n); |
|
| 338 | - elseif ($type === 'array') return $this->row_array($n); |
|
| 339 | - else return $this->custom_row_object($n, $type); |
|
| 331 | + if ($type === 'object') { |
|
| 332 | + return $this->row_object($n); |
|
| 333 | + } elseif ($type === 'array') { |
|
| 334 | + return $this->row_array($n); |
|
| 335 | + } else { |
|
| 336 | + return $this->custom_row_object($n, $type); |
|
| 337 | + } |
|
| 340 | 338 | } |
| 341 | 339 | |
| 342 | 340 | // -------------------------------------------------------------------- |
@@ -530,8 +528,7 @@ discard block |
||
| 530 | 528 | if ($type === 'array') |
| 531 | 529 | { |
| 532 | 530 | return $this->_fetch_assoc(); |
| 533 | - } |
|
| 534 | - elseif ($type === 'object') |
|
| 531 | + } elseif ($type === 'object') |
|
| 535 | 532 | { |
| 536 | 533 | return $this->_fetch_object(); |
| 537 | 534 | } |
@@ -58,28 +58,28 @@ discard block |
||
| 58 | 58 | * |
| 59 | 59 | * @var array |
| 60 | 60 | */ |
| 61 | - public $fields = array(); |
|
| 61 | + public $fields = array(); |
|
| 62 | 62 | |
| 63 | 63 | /** |
| 64 | 64 | * Keys data |
| 65 | 65 | * |
| 66 | 66 | * @var array |
| 67 | 67 | */ |
| 68 | - public $keys = array(); |
|
| 68 | + public $keys = array(); |
|
| 69 | 69 | |
| 70 | 70 | /** |
| 71 | 71 | * Primary Keys data |
| 72 | 72 | * |
| 73 | 73 | * @var array |
| 74 | 74 | */ |
| 75 | - public $primary_keys = array(); |
|
| 75 | + public $primary_keys = array(); |
|
| 76 | 76 | |
| 77 | 77 | /** |
| 78 | 78 | * Database character set |
| 79 | 79 | * |
| 80 | 80 | * @var string |
| 81 | 81 | */ |
| 82 | - public $db_char_set = ''; |
|
| 82 | + public $db_char_set = ''; |
|
| 83 | 83 | |
| 84 | 84 | // -------------------------------------------------------------------- |
| 85 | 85 | |
@@ -88,28 +88,28 @@ discard block |
||
| 88 | 88 | * |
| 89 | 89 | * @var string |
| 90 | 90 | */ |
| 91 | - protected $_create_database = 'CREATE DATABASE %s'; |
|
| 91 | + protected $_create_database = 'CREATE DATABASE %s'; |
|
| 92 | 92 | |
| 93 | 93 | /** |
| 94 | 94 | * DROP DATABASE statement |
| 95 | 95 | * |
| 96 | 96 | * @var string |
| 97 | 97 | */ |
| 98 | - protected $_drop_database = 'DROP DATABASE %s'; |
|
| 98 | + protected $_drop_database = 'DROP DATABASE %s'; |
|
| 99 | 99 | |
| 100 | 100 | /** |
| 101 | 101 | * CREATE TABLE statement |
| 102 | 102 | * |
| 103 | 103 | * @var string |
| 104 | 104 | */ |
| 105 | - protected $_create_table = "%s %s (%s\n)"; |
|
| 105 | + protected $_create_table = "%s %s (%s\n)"; |
|
| 106 | 106 | |
| 107 | 107 | /** |
| 108 | 108 | * CREATE TABLE IF statement |
| 109 | 109 | * |
| 110 | 110 | * @var string |
| 111 | 111 | */ |
| 112 | - protected $_create_table_if = 'CREATE TABLE IF NOT EXISTS'; |
|
| 112 | + protected $_create_table_if = 'CREATE TABLE IF NOT EXISTS'; |
|
| 113 | 113 | |
| 114 | 114 | /** |
| 115 | 115 | * CREATE TABLE keys flag |
@@ -119,42 +119,42 @@ discard block |
||
| 119 | 119 | * |
| 120 | 120 | * @var bool |
| 121 | 121 | */ |
| 122 | - protected $_create_table_keys = FALSE; |
|
| 122 | + protected $_create_table_keys = FALSE; |
|
| 123 | 123 | |
| 124 | 124 | /** |
| 125 | 125 | * DROP TABLE IF EXISTS statement |
| 126 | 126 | * |
| 127 | 127 | * @var string |
| 128 | 128 | */ |
| 129 | - protected $_drop_table_if = 'DROP TABLE IF EXISTS'; |
|
| 129 | + protected $_drop_table_if = 'DROP TABLE IF EXISTS'; |
|
| 130 | 130 | |
| 131 | 131 | /** |
| 132 | 132 | * RENAME TABLE statement |
| 133 | 133 | * |
| 134 | 134 | * @var string |
| 135 | 135 | */ |
| 136 | - protected $_rename_table = 'ALTER TABLE %s RENAME TO %s;'; |
|
| 136 | + protected $_rename_table = 'ALTER TABLE %s RENAME TO %s;'; |
|
| 137 | 137 | |
| 138 | 138 | /** |
| 139 | 139 | * UNSIGNED support |
| 140 | 140 | * |
| 141 | 141 | * @var bool|array |
| 142 | 142 | */ |
| 143 | - protected $_unsigned = TRUE; |
|
| 143 | + protected $_unsigned = TRUE; |
|
| 144 | 144 | |
| 145 | 145 | /** |
| 146 | 146 | * NULL value representation in CREATE/ALTER TABLE statements |
| 147 | 147 | * |
| 148 | 148 | * @var string |
| 149 | 149 | */ |
| 150 | - protected $_null = ''; |
|
| 150 | + protected $_null = ''; |
|
| 151 | 151 | |
| 152 | 152 | /** |
| 153 | 153 | * DEFAULT value representation in CREATE/ALTER TABLE statements |
| 154 | 154 | * |
| 155 | 155 | * @var string |
| 156 | 156 | */ |
| 157 | - protected $_default = ' DEFAULT '; |
|
| 157 | + protected $_default = ' DEFAULT '; |
|
| 158 | 158 | |
| 159 | 159 | // -------------------------------------------------------------------- |
| 160 | 160 | |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | */ |
| 167 | 167 | public function __construct(&$db) |
| 168 | 168 | { |
| 169 | - $this->db =& $db; |
|
| 169 | + $this->db = & $db; |
|
| 170 | 170 | log_message('info', 'Database Forge Class Initialized'); |
| 171 | 171 | } |
| 172 | 172 | |
@@ -183,8 +183,7 @@ discard block |
||
| 183 | 183 | if ($this->_create_database === FALSE) |
| 184 | 184 | { |
| 185 | 185 | return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE; |
| 186 | - } |
|
| 187 | - elseif ( ! $this->db->query(sprintf($this->_create_database, $this->db->escape_identifiers($db_name), $this->db->char_set, $this->db->dbcollat))) |
|
| 186 | + } elseif ( ! $this->db->query(sprintf($this->_create_database, $this->db->escape_identifiers($db_name), $this->db->char_set, $this->db->dbcollat))) |
|
| 188 | 187 | { |
| 189 | 188 | return ($this->db->db_debug) ? $this->db->display_error('db_unable_to_drop') : FALSE; |
| 190 | 189 | } |
@@ -210,8 +209,7 @@ discard block |
||
| 210 | 209 | if ($this->_drop_database === FALSE) |
| 211 | 210 | { |
| 212 | 211 | return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE; |
| 213 | - } |
|
| 214 | - elseif ( ! $this->db->query(sprintf($this->_drop_database, $this->db->escape_identifiers($db_name)))) |
|
| 212 | + } elseif ( ! $this->db->query(sprintf($this->_drop_database, $this->db->escape_identifiers($db_name)))) |
|
| 215 | 213 | { |
| 216 | 214 | return ($this->db->db_debug) ? $this->db->display_error('db_unable_to_drop') : FALSE; |
| 217 | 215 | } |
@@ -258,8 +256,7 @@ discard block |
||
| 258 | 256 | if ($primary === TRUE) |
| 259 | 257 | { |
| 260 | 258 | $this->primary_keys[] = $key; |
| 261 | - } |
|
| 262 | - else |
|
| 259 | + } else |
|
| 263 | 260 | { |
| 264 | 261 | $this->keys[] = $key; |
| 265 | 262 | } |
@@ -289,8 +286,7 @@ discard block |
||
| 289 | 286 | ) |
| 290 | 287 | )); |
| 291 | 288 | $this->add_key('id', TRUE); |
| 292 | - } |
|
| 293 | - else |
|
| 289 | + } else |
|
| 294 | 290 | { |
| 295 | 291 | if (strpos($field, ' ') === FALSE) |
| 296 | 292 | { |
@@ -324,8 +320,7 @@ discard block |
||
| 324 | 320 | if ($table === '') |
| 325 | 321 | { |
| 326 | 322 | show_error('A table name is required for that operation.'); |
| 327 | - } |
|
| 328 | - else |
|
| 323 | + } else |
|
| 329 | 324 | { |
| 330 | 325 | $table = $this->db->dbprefix.$table; |
| 331 | 326 | } |
@@ -381,8 +376,7 @@ discard block |
||
| 381 | 376 | if ($this->db->table_exists($table)) |
| 382 | 377 | { |
| 383 | 378 | return TRUE; |
| 384 | - } |
|
| 385 | - else |
|
| 379 | + } else |
|
| 386 | 380 | { |
| 387 | 381 | $if_not_exists = FALSE; |
| 388 | 382 | } |
@@ -502,8 +496,7 @@ discard block |
||
| 502 | 496 | { |
| 503 | 497 | return TRUE; |
| 504 | 498 | } |
| 505 | - } |
|
| 506 | - else |
|
| 499 | + } else |
|
| 507 | 500 | { |
| 508 | 501 | $sql = sprintf($this->_drop_table_if, $this->db->escape_identifiers($table)); |
| 509 | 502 | } |
@@ -527,8 +520,7 @@ discard block |
||
| 527 | 520 | { |
| 528 | 521 | show_error('A table name is required for that operation.'); |
| 529 | 522 | return FALSE; |
| 530 | - } |
|
| 531 | - elseif ($this->_rename_table === FALSE) |
|
| 523 | + } elseif ($this->_rename_table === FALSE) |
|
| 532 | 524 | { |
| 533 | 525 | return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE; |
| 534 | 526 | } |
@@ -740,8 +732,7 @@ discard block |
||
| 740 | 732 | if (isset($attributes['AFTER'])) |
| 741 | 733 | { |
| 742 | 734 | $field['after'] = $attributes['AFTER']; |
| 743 | - } |
|
| 744 | - elseif (isset($attributes['FIRST'])) |
|
| 735 | + } elseif (isset($attributes['FIRST'])) |
|
| 745 | 736 | { |
| 746 | 737 | $field['first'] = (bool) $attributes['FIRST']; |
| 747 | 738 | } |
@@ -754,13 +745,11 @@ discard block |
||
| 754 | 745 | if ($attributes['NULL'] === TRUE) |
| 755 | 746 | { |
| 756 | 747 | $field['null'] = empty($this->_null) ? '' : ' '.$this->_null; |
| 757 | - } |
|
| 758 | - else |
|
| 748 | + } else |
|
| 759 | 749 | { |
| 760 | 750 | $field['null'] = ' NOT NULL'; |
| 761 | 751 | } |
| 762 | - } |
|
| 763 | - elseif ($create_table === TRUE) |
|
| 752 | + } elseif ($create_table === TRUE) |
|
| 764 | 753 | { |
| 765 | 754 | $field['null'] = ' NOT NULL'; |
| 766 | 755 | } |
@@ -864,8 +853,7 @@ discard block |
||
| 864 | 853 | { |
| 865 | 854 | $field['unsigned'] = ' UNSIGNED'; |
| 866 | 855 | return; |
| 867 | - } |
|
| 868 | - elseif (is_string($key) && strcasecmp($attributes['TYPE'], $key) === 0) |
|
| 856 | + } elseif (is_string($key) && strcasecmp($attributes['TYPE'], $key) === 0) |
|
| 869 | 857 | { |
| 870 | 858 | $field['type'] = $key; |
| 871 | 859 | return; |
@@ -903,8 +891,7 @@ discard block |
||
| 903 | 891 | // Override the NULL attribute if that's our default |
| 904 | 892 | $attributes['NULL'] = TRUE; |
| 905 | 893 | $field['null'] = empty($this->_null) ? '' : ' '.$this->_null; |
| 906 | - } |
|
| 907 | - else |
|
| 894 | + } else |
|
| 908 | 895 | { |
| 909 | 896 | $field['default'] = $this->_default.$this->db->escape($attributes['DEFAULT']); |
| 910 | 897 | } |
@@ -998,8 +985,7 @@ discard block |
||
| 998 | 985 | continue; |
| 999 | 986 | } |
| 1000 | 987 | } |
| 1001 | - } |
|
| 1002 | - elseif ( ! isset($this->fields[$this->keys[$i]])) |
|
| 988 | + } elseif ( ! isset($this->fields[$this->keys[$i]])) |
|
| 1003 | 989 | { |
| 1004 | 990 | unset($this->keys[$i]); |
| 1005 | 991 | continue; |
@@ -103,8 +103,7 @@ discard block |
||
| 103 | 103 | if (isset($this->db->data_cache['db_names'])) |
| 104 | 104 | { |
| 105 | 105 | return $this->db->data_cache['db_names']; |
| 106 | - } |
|
| 107 | - elseif ($this->_list_databases === FALSE) |
|
| 106 | + } elseif ($this->_list_databases === FALSE) |
|
| 108 | 107 | { |
| 109 | 108 | return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE; |
| 110 | 109 | } |
@@ -387,8 +386,7 @@ discard block |
||
| 387 | 386 | { |
| 388 | 387 | $prefs['filename'] = (count($prefs['tables']) === 1 ? $prefs['tables'] : $this->db->database) |
| 389 | 388 | .date('Y-m-d_H-i', time()).'.sql'; |
| 390 | - } |
|
| 391 | - else |
|
| 389 | + } else |
|
| 392 | 390 | { |
| 393 | 391 | // If they included the .zip file extension we'll remove it |
| 394 | 392 | if (preg_match('|.+?\.zip$|', $prefs['filename'])) |
@@ -408,15 +406,17 @@ discard block |
||
| 408 | 406 | $CI->load->library('zip'); |
| 409 | 407 | $CI->zip->add_data($prefs['filename'], $this->_backup($prefs)); |
| 410 | 408 | return $CI->zip->get_zip(); |
| 411 | - } |
|
| 412 | - elseif ($prefs['format'] === 'txt') // Was a text file requested? |
|
| 409 | + } elseif ($prefs['format'] === 'txt') { |
|
| 410 | + // Was a text file requested? |
|
| 413 | 411 | { |
| 414 | 412 | return $this->_backup($prefs); |
| 415 | 413 | } |
| 416 | - elseif ($prefs['format'] === 'gzip') // Was a Gzip file requested? |
|
| 414 | + } elseif ($prefs['format'] === 'gzip') { |
|
| 415 | + // Was a Gzip file requested? |
|
| 417 | 416 | { |
| 418 | 417 | return gzencode($this->_backup($prefs)); |
| 419 | 418 | } |
| 419 | + } |
|
| 420 | 420 | |
| 421 | 421 | return; |
| 422 | 422 | } |
@@ -225,36 +225,36 @@ |
||
| 225 | 225 | |
| 226 | 226 | // -------------------------------------------------------------------- |
| 227 | 227 | |
| 228 | - /** |
|
| 229 | - * Generate CSV from a query result object |
|
| 230 | - * |
|
| 231 | - * @param object $query Query result object |
|
| 232 | - * @param string $delim Delimiter (default: ,) |
|
| 233 | - * @param string $newline Newline character (default: \n) |
|
| 234 | - * @param string $enclosure Enclosure (default: ") |
|
| 235 | - * @return string |
|
| 236 | - */ |
|
| 237 | - public function csv_from_result($query, $delim = ',', $newline = "\n", $enclosure = '"') |
|
| 238 | - { |
|
| 239 | - if ( ! is_object($query) OR ! method_exists($query, 'list_fields')) { |
|
| 240 | - error_log('You must submit a valid result object'); |
|
| 241 | - } |
|
| 242 | - $out = ''; |
|
| 243 | - // First generate the headings from the table column names |
|
| 244 | - foreach ($query->list_fields() as $name) { |
|
| 245 | - $out .= $enclosure.str_replace($enclosure, $enclosure.$enclosure, $name).$enclosure.$delim; |
|
| 246 | - } |
|
| 247 | - $out = substr($out, 0, -strlen($delim)).$newline; |
|
| 248 | - // Next blast through the result array and build out the rows |
|
| 249 | - while ($row = $query->unbuffered_row('array')) { |
|
| 250 | - $line = array(); |
|
| 251 | - foreach ($row as $ite) { |
|
| 252 | - $line[] = $enclosure.str_replace($enclosure, $enclosure.$enclosure, $item).$enclosure; |
|
| 253 | - } |
|
| 254 | - $out .= implode($delim, $line).$newline; |
|
| 255 | - } |
|
| 256 | - return $out; |
|
| 257 | - } |
|
| 228 | + /** |
|
| 229 | + * Generate CSV from a query result object |
|
| 230 | + * |
|
| 231 | + * @param object $query Query result object |
|
| 232 | + * @param string $delim Delimiter (default: ,) |
|
| 233 | + * @param string $newline Newline character (default: \n) |
|
| 234 | + * @param string $enclosure Enclosure (default: ") |
|
| 235 | + * @return string |
|
| 236 | + */ |
|
| 237 | + public function csv_from_result($query, $delim = ',', $newline = "\n", $enclosure = '"') |
|
| 238 | + { |
|
| 239 | + if ( ! is_object($query) OR ! method_exists($query, 'list_fields')) { |
|
| 240 | + error_log('You must submit a valid result object'); |
|
| 241 | + } |
|
| 242 | + $out = ''; |
|
| 243 | + // First generate the headings from the table column names |
|
| 244 | + foreach ($query->list_fields() as $name) { |
|
| 245 | + $out .= $enclosure.str_replace($enclosure, $enclosure.$enclosure, $name).$enclosure.$delim; |
|
| 246 | + } |
|
| 247 | + $out = substr($out, 0, -strlen($delim)).$newline; |
|
| 248 | + // Next blast through the result array and build out the rows |
|
| 249 | + while ($row = $query->unbuffered_row('array')) { |
|
| 250 | + $line = array(); |
|
| 251 | + foreach ($row as $ite) { |
|
| 252 | + $line[] = $enclosure.str_replace($enclosure, $enclosure.$enclosure, $item).$enclosure; |
|
| 253 | + } |
|
| 254 | + $out .= implode($delim, $line).$newline; |
|
| 255 | + } |
|
| 256 | + return $out; |
|
| 257 | + } |
|
| 258 | 258 | |
| 259 | 259 | // -------------------------------------------------------------------- |
| 260 | 260 | |
@@ -60,21 +60,21 @@ discard block |
||
| 60 | 60 | * |
| 61 | 61 | * @var string |
| 62 | 62 | */ |
| 63 | - protected $_list_databases = FALSE; |
|
| 63 | + protected $_list_databases = FALSE; |
|
| 64 | 64 | |
| 65 | 65 | /** |
| 66 | 66 | * OPTIMIZE TABLE statement |
| 67 | 67 | * |
| 68 | 68 | * @var string |
| 69 | 69 | */ |
| 70 | - protected $_optimize_table = FALSE; |
|
| 70 | + protected $_optimize_table = FALSE; |
|
| 71 | 71 | |
| 72 | 72 | /** |
| 73 | 73 | * REPAIR TABLE statement |
| 74 | 74 | * |
| 75 | 75 | * @var string |
| 76 | 76 | */ |
| 77 | - protected $_repair_table = FALSE; |
|
| 77 | + protected $_repair_table = FALSE; |
|
| 78 | 78 | |
| 79 | 79 | // -------------------------------------------------------------------- |
| 80 | 80 | |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | */ |
| 87 | 87 | public function __construct(&$db) |
| 88 | 88 | { |
| 89 | - $this->db =& $db; |
|
| 89 | + $this->db = & $db; |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | // -------------------------------------------------------------------- |
@@ -395,7 +395,7 @@ discard block |
||
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | // Load the Zip class and output it |
| 398 | - $CI =& get_instance(); |
|
| 398 | + $CI = & get_instance(); |
|
| 399 | 399 | $CI->load->library('zip'); |
| 400 | 400 | $CI->zip->add_data($prefs['filename'], $this->_backup($prefs)); |
| 401 | 401 | return $CI->zip->get_zip(); |
@@ -112,12 +112,12 @@ |
||
| 112 | 112 | $field_data = $this->result_id->fetch_fields(); |
| 113 | 113 | for ($i = 0, $c = count($field_data); $i < $c; $i++) |
| 114 | 114 | { |
| 115 | - $retval[$i] = new stdClass(); |
|
| 115 | + $retval[$i] = new stdClass(); |
|
| 116 | 116 | $retval[$i]->name = $field_data[$i]->name; |
| 117 | 117 | $retval[$i]->type = static::_get_field_type($field_data[$i]->type); |
| 118 | 118 | $retval[$i]->max_length = $field_data[$i]->max_length; |
| 119 | 119 | $retval[$i]->primary_key = (int) ($field_data[$i]->flags & MYSQLI_PRI_KEY_FLAG); |
| 120 | - $retval[$i]->default = $field_data[$i]->def; |
|
| 120 | + $retval[$i]->default = $field_data[$i]->def; |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | return $retval; |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | * |
| 56 | 56 | * @var string |
| 57 | 57 | */ |
| 58 | - protected $_create_database = 'CREATE DATABASE %s CHARACTER SET %s COLLATE %s'; |
|
| 58 | + protected $_create_database = 'CREATE DATABASE %s CHARACTER SET %s COLLATE %s'; |
|
| 59 | 59 | |
| 60 | 60 | /** |
| 61 | 61 | * CREATE TABLE keys flag |
@@ -65,14 +65,14 @@ discard block |
||
| 65 | 65 | * |
| 66 | 66 | * @var bool |
| 67 | 67 | */ |
| 68 | - protected $_create_table_keys = TRUE; |
|
| 68 | + protected $_create_table_keys = TRUE; |
|
| 69 | 69 | |
| 70 | 70 | /** |
| 71 | 71 | * UNSIGNED support |
| 72 | 72 | * |
| 73 | 73 | * @var array |
| 74 | 74 | */ |
| 75 | - protected $_unsigned = array( |
|
| 75 | + protected $_unsigned = array( |
|
| 76 | 76 | 'TINYINT', |
| 77 | 77 | 'SMALLINT', |
| 78 | 78 | 'MEDIUMINT', |
@@ -152,14 +152,12 @@ discard block |
||
| 152 | 152 | $field[$i] = ($alter_type === 'ADD') |
| 153 | 153 | ? "\n\tADD ".$field[$i]['_literal'] |
| 154 | 154 | : "\n\tMODIFY ".$field[$i]['_literal']; |
| 155 | - } |
|
| 156 | - else |
|
| 155 | + } else |
|
| 157 | 156 | { |
| 158 | 157 | if ($alter_type === 'ADD') |
| 159 | 158 | { |
| 160 | 159 | $field[$i]['_literal'] = "\n\tADD "; |
| 161 | - } |
|
| 162 | - else |
|
| 160 | + } else |
|
| 163 | 161 | { |
| 164 | 162 | $field[$i]['_literal'] = empty($field[$i]['new_name']) ? "\n\tMODIFY " : "\n\tCHANGE "; |
| 165 | 163 | } |
@@ -225,8 +223,7 @@ discard block |
||
| 225 | 223 | continue; |
| 226 | 224 | } |
| 227 | 225 | } |
| 228 | - } |
|
| 229 | - elseif ( ! isset($this->fields[$this->keys[$i]])) |
|
| 226 | + } elseif ( ! isset($this->fields[$this->keys[$i]])) |
|
| 230 | 227 | { |
| 231 | 228 | unset($this->keys[$i]); |
| 232 | 229 | continue; |
@@ -55,21 +55,21 @@ discard block |
||
| 55 | 55 | * |
| 56 | 56 | * @var string |
| 57 | 57 | */ |
| 58 | - protected $_list_databases = 'SHOW DATABASES'; |
|
| 58 | + protected $_list_databases = 'SHOW DATABASES'; |
|
| 59 | 59 | |
| 60 | 60 | /** |
| 61 | 61 | * OPTIMIZE TABLE statement |
| 62 | 62 | * |
| 63 | 63 | * @var string |
| 64 | 64 | */ |
| 65 | - protected $_optimize_table = 'OPTIMIZE TABLE %s'; |
|
| 65 | + protected $_optimize_table = 'OPTIMIZE TABLE %s'; |
|
| 66 | 66 | |
| 67 | 67 | /** |
| 68 | 68 | * REPAIR TABLE statement |
| 69 | 69 | * |
| 70 | 70 | * @var string |
| 71 | 71 | */ |
| 72 | - protected $_repair_table = 'REPAIR TABLE %s'; |
|
| 72 | + protected $_repair_table = 'REPAIR TABLE %s'; |
|
| 73 | 73 | |
| 74 | 74 | // -------------------------------------------------------------------- |
| 75 | 75 | |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | $output .= 'SET foreign_key_checks = 0;'.$newline; |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - foreach ( (array) $tables as $table) |
|
| 101 | + foreach ((array) $tables as $table) |
|
| 102 | 102 | { |
| 103 | 103 | // Is the table in the "ignore" list? |
| 104 | 104 | if (in_array($table, (array) $ignore, TRUE)) |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | // Trim off the end comma |
| 172 | - $field_str = preg_replace('/, $/' , '', $field_str); |
|
| 172 | + $field_str = preg_replace('/, $/', '', $field_str); |
|
| 173 | 173 | |
| 174 | 174 | // Build the insert string |
| 175 | 175 | foreach ($query->result_array() as $row) |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | // Remove the comma at the end of the string |
| 199 | - $val_str = preg_replace('/, $/' , '', $val_str); |
|
| 199 | + $val_str = preg_replace('/, $/', '', $val_str); |
|
| 200 | 200 | |
| 201 | 201 | // Build the INSERT string |
| 202 | 202 | $output .= 'INSERT INTO '.$this->db->protect_identifiers($table).' ('.$field_str.') VALUES ('.$val_str.');'.$newline; |
@@ -183,8 +183,7 @@ |
||
| 183 | 183 | if ($v === NULL) |
| 184 | 184 | { |
| 185 | 185 | $val_str .= 'NULL'; |
| 186 | - } |
|
| 187 | - else |
|
| 186 | + } else |
|
| 188 | 187 | { |
| 189 | 188 | // Escape the data if it's not an integer |
| 190 | 189 | $val_str .= ($is_int[$i] === FALSE) ? $this->db->escape($v) : $v; |
@@ -166,9 +166,9 @@ discard block |
||
| 166 | 166 | if (is_array($this->encrypt)) |
| 167 | 167 | { |
| 168 | 168 | $ssl = array(); |
| 169 | - empty($this->encrypt['ssl_key']) OR $ssl['key'] = $this->encrypt['ssl_key']; |
|
| 170 | - empty($this->encrypt['ssl_cert']) OR $ssl['cert'] = $this->encrypt['ssl_cert']; |
|
| 171 | - empty($this->encrypt['ssl_ca']) OR $ssl['ca'] = $this->encrypt['ssl_ca']; |
|
| 169 | + empty($this->encrypt['ssl_key']) OR $ssl['key'] = $this->encrypt['ssl_key']; |
|
| 170 | + empty($this->encrypt['ssl_cert']) OR $ssl['cert'] = $this->encrypt['ssl_cert']; |
|
| 171 | + empty($this->encrypt['ssl_ca']) OR $ssl['ca'] = $this->encrypt['ssl_ca']; |
|
| 172 | 172 | empty($this->encrypt['ssl_capath']) OR $ssl['capath'] = $this->encrypt['ssl_capath']; |
| 173 | 173 | empty($this->encrypt['ssl_cipher']) OR $ssl['cipher'] = $this->encrypt['ssl_cipher']; |
| 174 | 174 | |
@@ -194,9 +194,9 @@ discard block |
||
| 194 | 194 | |
| 195 | 195 | $client_flags |= MYSQLI_CLIENT_SSL; |
| 196 | 196 | $this->_mysqli->ssl_set( |
| 197 | - isset($ssl['key']) ? $ssl['key'] : NULL, |
|
| 198 | - isset($ssl['cert']) ? $ssl['cert'] : NULL, |
|
| 199 | - isset($ssl['ca']) ? $ssl['ca'] : NULL, |
|
| 197 | + isset($ssl['key']) ? $ssl['key'] : NULL, |
|
| 198 | + isset($ssl['cert']) ? $ssl['cert'] : NULL, |
|
| 199 | + isset($ssl['ca']) ? $ssl['ca'] : NULL, |
|
| 200 | 200 | isset($ssl['capath']) ? $ssl['capath'] : NULL, |
| 201 | 201 | isset($ssl['cipher']) ? $ssl['cipher'] : NULL |
| 202 | 202 | ); |
@@ -475,16 +475,16 @@ discard block |
||
| 475 | 475 | $retval = array(); |
| 476 | 476 | for ($i = 0, $c = count($query); $i < $c; $i++) |
| 477 | 477 | { |
| 478 | - $retval[$i] = new stdClass(); |
|
| 479 | - $retval[$i]->name = $query[$i]->Field; |
|
| 478 | + $retval[$i] = new stdClass(); |
|
| 479 | + $retval[$i]->name = $query[$i]->Field; |
|
| 480 | 480 | |
| 481 | 481 | sscanf($query[$i]->Type, '%[a-z](%d)', |
| 482 | 482 | $retval[$i]->type, |
| 483 | 483 | $retval[$i]->max_length |
| 484 | 484 | ); |
| 485 | 485 | |
| 486 | - $retval[$i]->default = $query[$i]->Default; |
|
| 487 | - $retval[$i]->primary_key = (int) ($query[$i]->Key === 'PRI'); |
|
| 486 | + $retval[$i]->default = $query[$i]->Default; |
|
| 487 | + $retval[$i]->primary_key = (int) ($query[$i]->Key === 'PRI'); |
|
| 488 | 488 | } |
| 489 | 489 | |
| 490 | 490 | return $retval; |
@@ -127,8 +127,7 @@ discard block |
||
| 127 | 127 | $hostname = NULL; |
| 128 | 128 | $port = NULL; |
| 129 | 129 | $socket = $this->hostname; |
| 130 | - } |
|
| 131 | - else |
|
| 130 | + } else |
|
| 132 | 131 | { |
| 133 | 132 | $hostname = ($persistent === TRUE) |
| 134 | 133 | ? 'p:'.$this->hostname : $this->hostname; |
@@ -146,8 +145,7 @@ discard block |
||
| 146 | 145 | if ($this->stricton) |
| 147 | 146 | { |
| 148 | 147 | $this->_mysqli->options(MYSQLI_INIT_COMMAND, 'SET SESSION sql_mode = CONCAT(@@sql_mode, ",", "STRICT_ALL_TABLES")'); |
| 149 | - } |
|
| 150 | - else |
|
| 148 | + } else |
|
| 151 | 149 | { |
| 152 | 150 | $this->_mysqli->options(MYSQLI_INIT_COMMAND, |
| 153 | 151 | 'SET SESSION sql_mode = |
@@ -54,67 +54,67 @@ discard block |
||
| 54 | 54 | * @link https://codeigniter.com/user_guide/database/ |
| 55 | 55 | */ |
| 56 | 56 | class CI_DB_mysqli_driver extends CI_DB_driver { |
| 57 | - /** |
|
| 58 | - * Database driver |
|
| 59 | - * |
|
| 60 | - * @var string |
|
| 61 | - */ |
|
| 62 | - public $dbdriver = 'mysqli'; |
|
| 63 | - /** |
|
| 64 | - * Compression flag |
|
| 65 | - * |
|
| 66 | - * @var bool |
|
| 67 | - */ |
|
| 68 | - public $compress = FALSE; |
|
| 69 | - /** |
|
| 70 | - * DELETE hack flag |
|
| 71 | - * |
|
| 72 | - * Whether to use the MySQL "delete hack" which allows the number |
|
| 73 | - * of affected rows to be shown. Uses a preg_replace when enabled, |
|
| 74 | - * adding a bit more processing to all queries. |
|
| 75 | - * |
|
| 76 | - * @var bool |
|
| 77 | - */ |
|
| 78 | - public $delete_hack = TRUE; |
|
| 79 | - /** |
|
| 80 | - * Strict ON flag |
|
| 81 | - * |
|
| 82 | - * Whether we're running in strict SQL mode. |
|
| 83 | - * |
|
| 84 | - * @var bool |
|
| 85 | - */ |
|
| 86 | - public $stricton; |
|
| 87 | - /** |
|
| 88 | - * Identifier escape character |
|
| 89 | - * |
|
| 90 | - * @var string |
|
| 91 | - */ |
|
| 92 | - protected $_escape_char = '`'; |
|
| 93 | - /** |
|
| 94 | - * MySQLi object |
|
| 95 | - * |
|
| 96 | - * Has to be preserved without being assigned to $conn_id. |
|
| 97 | - * |
|
| 98 | - * @var MySQLi |
|
| 99 | - */ |
|
| 100 | - protected $_mysqli; |
|
| 101 | - /** |
|
| 102 | - * |
|
| 103 | - * @param array $params |
|
| 104 | - */ |
|
| 105 | - public function __construct(array $params) |
|
| 106 | - { |
|
| 107 | - parent::__construct($params); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Database connection |
|
| 112 | - * |
|
| 113 | - * @param bool $persistent |
|
| 114 | - * @return object |
|
| 115 | - **/ |
|
| 116 | - public function db_connect($persistent = FALSE) |
|
| 117 | - { |
|
| 57 | + /** |
|
| 58 | + * Database driver |
|
| 59 | + * |
|
| 60 | + * @var string |
|
| 61 | + */ |
|
| 62 | + public $dbdriver = 'mysqli'; |
|
| 63 | + /** |
|
| 64 | + * Compression flag |
|
| 65 | + * |
|
| 66 | + * @var bool |
|
| 67 | + */ |
|
| 68 | + public $compress = FALSE; |
|
| 69 | + /** |
|
| 70 | + * DELETE hack flag |
|
| 71 | + * |
|
| 72 | + * Whether to use the MySQL "delete hack" which allows the number |
|
| 73 | + * of affected rows to be shown. Uses a preg_replace when enabled, |
|
| 74 | + * adding a bit more processing to all queries. |
|
| 75 | + * |
|
| 76 | + * @var bool |
|
| 77 | + */ |
|
| 78 | + public $delete_hack = TRUE; |
|
| 79 | + /** |
|
| 80 | + * Strict ON flag |
|
| 81 | + * |
|
| 82 | + * Whether we're running in strict SQL mode. |
|
| 83 | + * |
|
| 84 | + * @var bool |
|
| 85 | + */ |
|
| 86 | + public $stricton; |
|
| 87 | + /** |
|
| 88 | + * Identifier escape character |
|
| 89 | + * |
|
| 90 | + * @var string |
|
| 91 | + */ |
|
| 92 | + protected $_escape_char = '`'; |
|
| 93 | + /** |
|
| 94 | + * MySQLi object |
|
| 95 | + * |
|
| 96 | + * Has to be preserved without being assigned to $conn_id. |
|
| 97 | + * |
|
| 98 | + * @var MySQLi |
|
| 99 | + */ |
|
| 100 | + protected $_mysqli; |
|
| 101 | + /** |
|
| 102 | + * |
|
| 103 | + * @param array $params |
|
| 104 | + */ |
|
| 105 | + public function __construct(array $params) |
|
| 106 | + { |
|
| 107 | + parent::__construct($params); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Database connection |
|
| 112 | + * |
|
| 113 | + * @param bool $persistent |
|
| 114 | + * @return object |
|
| 115 | + **/ |
|
| 116 | + public function db_connect($persistent = FALSE) |
|
| 117 | + { |
|
| 118 | 118 | // Do we have a socket path? |
| 119 | 119 | if ($this->hostname[0] === '/') |
| 120 | 120 | { |
@@ -215,22 +215,22 @@ discard block |
||
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | return FALSE; |
| 218 | - } |
|
| 218 | + } |
|
| 219 | 219 | |
| 220 | 220 | // -------------------------------------------------------------------- |
| 221 | 221 | |
| 222 | - /** |
|
| 223 | - * Reconnect |
|
| 224 | - * Keep / reestablish the db connection if no queries have been |
|
| 225 | - * sent for a length of time exceeding the server's idle timeout |
|
| 226 | - * @return void |
|
| 227 | - */ |
|
| 228 | - public function reconnect() |
|
| 229 | - { |
|
| 230 | - if ($this->conn_id !== FALSE && $this->conn_id->ping() === FALSE) { |
|
| 231 | - $this->conn_id = FALSE; |
|
| 232 | - } |
|
| 233 | - } |
|
| 222 | + /** |
|
| 223 | + * Reconnect |
|
| 224 | + * Keep / reestablish the db connection if no queries have been |
|
| 225 | + * sent for a length of time exceeding the server's idle timeout |
|
| 226 | + * @return void |
|
| 227 | + */ |
|
| 228 | + public function reconnect() |
|
| 229 | + { |
|
| 230 | + if ($this->conn_id !== FALSE && $this->conn_id->ping() === FALSE) { |
|
| 231 | + $this->conn_id = FALSE; |
|
| 232 | + } |
|
| 233 | + } |
|
| 234 | 234 | /** |
| 235 | 235 | * Select the database |
| 236 | 236 | * |
@@ -299,33 +299,33 @@ discard block |
||
| 299 | 299 | |
| 300 | 300 | // -------------------------------------------------------------------- |
| 301 | 301 | |
| 302 | - /** |
|
| 303 | - * Prep the query |
|
| 304 | - * |
|
| 305 | - * If needed, each database adapter can prep the query string |
|
| 306 | - * |
|
| 307 | - * @param string $sql an SQL query |
|
| 308 | - * @return string |
|
| 309 | - */ |
|
| 310 | - protected function _prep_query($sql) |
|
| 311 | - { |
|
| 312 | - // mysqli_affected_rows() returns 0 for "DELETE FROM TABLE" queries. This hack |
|
| 313 | - // modifies the query so that it a proper number of affected rows is returned. |
|
| 314 | - if ($this->delete_hack === TRUE && preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $sql)) { |
|
| 315 | - return trim($sql).' WHERE 1=1'; |
|
| 316 | - } |
|
| 317 | - return $sql; |
|
| 318 | - } |
|
| 319 | - /** |
|
| 320 | - * Begin Transaction |
|
| 321 | - * |
|
| 322 | - * @return bool |
|
| 323 | - */ |
|
| 324 | - protected function _trans_begin() |
|
| 325 | - { |
|
| 326 | - $this->conn_id->autocommit(FALSE); |
|
| 327 | - return $this->simple_query('START TRANSACTION'); // can also be BEGIN or BEGIN WORK |
|
| 328 | - } |
|
| 302 | + /** |
|
| 303 | + * Prep the query |
|
| 304 | + * |
|
| 305 | + * If needed, each database adapter can prep the query string |
|
| 306 | + * |
|
| 307 | + * @param string $sql an SQL query |
|
| 308 | + * @return string |
|
| 309 | + */ |
|
| 310 | + protected function _prep_query($sql) |
|
| 311 | + { |
|
| 312 | + // mysqli_affected_rows() returns 0 for "DELETE FROM TABLE" queries. This hack |
|
| 313 | + // modifies the query so that it a proper number of affected rows is returned. |
|
| 314 | + if ($this->delete_hack === TRUE && preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $sql)) { |
|
| 315 | + return trim($sql).' WHERE 1=1'; |
|
| 316 | + } |
|
| 317 | + return $sql; |
|
| 318 | + } |
|
| 319 | + /** |
|
| 320 | + * Begin Transaction |
|
| 321 | + * |
|
| 322 | + * @return bool |
|
| 323 | + */ |
|
| 324 | + protected function _trans_begin() |
|
| 325 | + { |
|
| 326 | + $this->conn_id->autocommit(FALSE); |
|
| 327 | + return $this->simple_query('START TRANSACTION'); // can also be BEGIN or BEGIN WORK |
|
| 328 | + } |
|
| 329 | 329 | |
| 330 | 330 | // -------------------------------------------------------------------- |
| 331 | 331 | |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | * |
| 97 | 97 | * @var string |
| 98 | 98 | */ |
| 99 | - public $dbdriver = 'mysqli'; |
|
| 99 | + public $dbdriver = 'mysqli'; |
|
| 100 | 100 | |
| 101 | 101 | /** |
| 102 | 102 | * Sub-driver |
@@ -111,63 +111,63 @@ discard block |
||
| 111 | 111 | * |
| 112 | 112 | * @var string |
| 113 | 113 | */ |
| 114 | - public $dbprefix = ''; |
|
| 114 | + public $dbprefix = ''; |
|
| 115 | 115 | |
| 116 | 116 | /** |
| 117 | 117 | * Character set |
| 118 | 118 | * |
| 119 | 119 | * @var string |
| 120 | 120 | */ |
| 121 | - public $char_set = 'utf8'; |
|
| 121 | + public $char_set = 'utf8'; |
|
| 122 | 122 | |
| 123 | 123 | /** |
| 124 | 124 | * Collation |
| 125 | 125 | * |
| 126 | 126 | * @var string |
| 127 | 127 | */ |
| 128 | - public $dbcollat = 'utf8_general_ci'; |
|
| 128 | + public $dbcollat = 'utf8_general_ci'; |
|
| 129 | 129 | |
| 130 | 130 | /** |
| 131 | 131 | * Encryption flag/data |
| 132 | 132 | * |
| 133 | 133 | * @var mixed |
| 134 | 134 | */ |
| 135 | - public $encrypt = FALSE; |
|
| 135 | + public $encrypt = FALSE; |
|
| 136 | 136 | |
| 137 | 137 | /** |
| 138 | 138 | * Swap Prefix |
| 139 | 139 | * |
| 140 | 140 | * @var string |
| 141 | 141 | */ |
| 142 | - public $swap_pre = ''; |
|
| 142 | + public $swap_pre = ''; |
|
| 143 | 143 | |
| 144 | 144 | /** |
| 145 | 145 | * Database port |
| 146 | 146 | * |
| 147 | 147 | * @var int |
| 148 | 148 | */ |
| 149 | - public $port = ''; |
|
| 149 | + public $port = ''; |
|
| 150 | 150 | |
| 151 | 151 | /** |
| 152 | 152 | * Persistent connection flag |
| 153 | 153 | * |
| 154 | 154 | * @var bool |
| 155 | 155 | */ |
| 156 | - public $pconnect = FALSE; |
|
| 156 | + public $pconnect = FALSE; |
|
| 157 | 157 | |
| 158 | 158 | /** |
| 159 | 159 | * Connection ID |
| 160 | 160 | * |
| 161 | 161 | * @var object|resource |
| 162 | 162 | */ |
| 163 | - public $conn_id = FALSE; |
|
| 163 | + public $conn_id = FALSE; |
|
| 164 | 164 | |
| 165 | 165 | /** |
| 166 | 166 | * Result ID |
| 167 | 167 | * |
| 168 | 168 | * @var object|resource |
| 169 | 169 | */ |
| 170 | - public $result_id = FALSE; |
|
| 170 | + public $result_id = FALSE; |
|
| 171 | 171 | |
| 172 | 172 | /** |
| 173 | 173 | * Debug flag |
@@ -176,21 +176,21 @@ discard block |
||
| 176 | 176 | * |
| 177 | 177 | * @var bool |
| 178 | 178 | */ |
| 179 | - public $db_debug = FALSE; |
|
| 179 | + public $db_debug = FALSE; |
|
| 180 | 180 | |
| 181 | 181 | /** |
| 182 | 182 | * Benchmark time |
| 183 | 183 | * |
| 184 | 184 | * @var int |
| 185 | 185 | */ |
| 186 | - public $benchmark = 0; |
|
| 186 | + public $benchmark = 0; |
|
| 187 | 187 | |
| 188 | 188 | /** |
| 189 | 189 | * Executed queries count |
| 190 | 190 | * |
| 191 | 191 | * @var int |
| 192 | 192 | */ |
| 193 | - public $query_count = 0; |
|
| 193 | + public $query_count = 0; |
|
| 194 | 194 | |
| 195 | 195 | /** |
| 196 | 196 | * Bind marker |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | * |
| 200 | 200 | * @var string |
| 201 | 201 | */ |
| 202 | - public $bind_marker = '?'; |
|
| 202 | + public $bind_marker = '?'; |
|
| 203 | 203 | |
| 204 | 204 | /** |
| 205 | 205 | * Save queries flag |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | * |
| 209 | 209 | * @var bool |
| 210 | 210 | */ |
| 211 | - public $save_queries = TRUE; |
|
| 211 | + public $save_queries = TRUE; |
|
| 212 | 212 | |
| 213 | 213 | /** |
| 214 | 214 | * Queries list |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | * @see CI_DB_driver::$save_queries |
| 217 | 217 | * @var string[] |
| 218 | 218 | */ |
| 219 | - public $queries = array(); |
|
| 219 | + public $queries = array(); |
|
| 220 | 220 | |
| 221 | 221 | /** |
| 222 | 222 | * Query times |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | * |
| 226 | 226 | * @var array |
| 227 | 227 | */ |
| 228 | - public $query_times = array(); |
|
| 228 | + public $query_times = array(); |
|
| 229 | 229 | |
| 230 | 230 | /** |
| 231 | 231 | * Data cache |
@@ -234,28 +234,28 @@ discard block |
||
| 234 | 234 | * |
| 235 | 235 | * @var array |
| 236 | 236 | */ |
| 237 | - public $data_cache = array(); |
|
| 237 | + public $data_cache = array(); |
|
| 238 | 238 | |
| 239 | 239 | /** |
| 240 | 240 | * Transaction enabled flag |
| 241 | 241 | * |
| 242 | 242 | * @var bool |
| 243 | 243 | */ |
| 244 | - public $trans_enabled = TRUE; |
|
| 244 | + public $trans_enabled = TRUE; |
|
| 245 | 245 | |
| 246 | 246 | /** |
| 247 | 247 | * Strict transaction mode flag |
| 248 | 248 | * |
| 249 | 249 | * @var bool |
| 250 | 250 | */ |
| 251 | - public $trans_strict = TRUE; |
|
| 251 | + public $trans_strict = TRUE; |
|
| 252 | 252 | |
| 253 | 253 | /** |
| 254 | 254 | * Transaction depth level |
| 255 | 255 | * |
| 256 | 256 | * @var int |
| 257 | 257 | */ |
| 258 | - protected $_trans_depth = 0; |
|
| 258 | + protected $_trans_depth = 0; |
|
| 259 | 259 | |
| 260 | 260 | /** |
| 261 | 261 | * Transaction status flag |
@@ -264,7 +264,7 @@ discard block |
||
| 264 | 264 | * |
| 265 | 265 | * @var bool |
| 266 | 266 | */ |
| 267 | - protected $_trans_status = TRUE; |
|
| 267 | + protected $_trans_status = TRUE; |
|
| 268 | 268 | |
| 269 | 269 | /** |
| 270 | 270 | * Transaction failure flag |
@@ -273,28 +273,28 @@ discard block |
||
| 273 | 273 | * |
| 274 | 274 | * @var bool |
| 275 | 275 | */ |
| 276 | - protected $_trans_failure = FALSE; |
|
| 276 | + protected $_trans_failure = FALSE; |
|
| 277 | 277 | |
| 278 | 278 | /** |
| 279 | 279 | * Cache On flag |
| 280 | 280 | * |
| 281 | 281 | * @var bool |
| 282 | 282 | */ |
| 283 | - public $cache_on = FALSE; |
|
| 283 | + public $cache_on = FALSE; |
|
| 284 | 284 | |
| 285 | 285 | /** |
| 286 | 286 | * Cache directory path |
| 287 | 287 | * |
| 288 | 288 | * @var bool |
| 289 | 289 | */ |
| 290 | - public $cachedir = ''; |
|
| 290 | + public $cachedir = ''; |
|
| 291 | 291 | |
| 292 | 292 | /** |
| 293 | 293 | * Cache auto-delete flag |
| 294 | 294 | * |
| 295 | 295 | * @var bool |
| 296 | 296 | */ |
| 297 | - public $cache_autodel = FALSE; |
|
| 297 | + public $cache_autodel = FALSE; |
|
| 298 | 298 | |
| 299 | 299 | /** |
| 300 | 300 | * DB Cache object |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | * |
| 310 | 310 | * @var bool |
| 311 | 311 | */ |
| 312 | - protected $_protect_identifiers = TRUE; |
|
| 312 | + protected $_protect_identifiers = TRUE; |
|
| 313 | 313 | |
| 314 | 314 | /** |
| 315 | 315 | * List of reserved identifiers |
@@ -318,7 +318,7 @@ discard block |
||
| 318 | 318 | * |
| 319 | 319 | * @var string[] |
| 320 | 320 | */ |
| 321 | - protected $_reserved_identifiers = array('*'); |
|
| 321 | + protected $_reserved_identifiers = array('*'); |
|
| 322 | 322 | |
| 323 | 323 | /** |
| 324 | 324 | * Identifier escape character |
@@ -721,8 +721,8 @@ discard block |
||
| 721 | 721 | } |
| 722 | 722 | |
| 723 | 723 | // Load and instantiate the result driver |
| 724 | - $driver = $this->load_rdriver(); |
|
| 725 | - $RES = new $driver($this); |
|
| 724 | + $driver = $this->load_rdriver(); |
|
| 725 | + $RES = new $driver($this); |
|
| 726 | 726 | |
| 727 | 727 | // Is query caching enabled? If so, we'll serialize the |
| 728 | 728 | // result object and save it to a cache file. |
@@ -735,13 +735,13 @@ discard block |
||
| 735 | 735 | // result object, so we'll have to compile the data |
| 736 | 736 | // and save it) |
| 737 | 737 | $CR = new CI_DB_result($this); |
| 738 | - $CR->result_object = $RES->result_object(); |
|
| 739 | - $CR->result_array = $RES->result_array(); |
|
| 740 | - $CR->num_rows = $RES->num_rows(); |
|
| 738 | + $CR->result_object = $RES->result_object(); |
|
| 739 | + $CR->result_array = $RES->result_array(); |
|
| 740 | + $CR->num_rows = $RES->num_rows(); |
|
| 741 | 741 | |
| 742 | 742 | // Reset these since cached objects can not utilize resource IDs. |
| 743 | - $CR->conn_id = NULL; |
|
| 744 | - $CR->result_id = NULL; |
|
| 743 | + $CR->conn_id = NULL; |
|
| 744 | + $CR->result_id = NULL; |
|
| 745 | 745 | |
| 746 | 746 | $this->CACHE->write($sql, $CR); |
| 747 | 747 | } |
@@ -1557,17 +1557,17 @@ discard block |
||
| 1557 | 1557 | ? '\s+'.preg_quote(trim(sprintf($this->_like_escape_str, $this->_like_escape_chr)), '/') |
| 1558 | 1558 | : ''; |
| 1559 | 1559 | $_operators = array( |
| 1560 | - '\s*(?:<|>|!)?=\s*', // =, <=, >=, != |
|
| 1561 | - '\s*<>?\s*', // <, <> |
|
| 1562 | - '\s*>\s*', // > |
|
| 1563 | - '\s+IS NULL', // IS NULL |
|
| 1564 | - '\s+IS NOT NULL', // IS NOT NULL |
|
| 1565 | - '\s+EXISTS\s*\(.*\)', // EXISTS(sql) |
|
| 1566 | - '\s+NOT EXISTS\s*\(.*\)', // NOT EXISTS(sql) |
|
| 1567 | - '\s+BETWEEN\s+', // BETWEEN value AND value |
|
| 1568 | - '\s+IN\s*\(.*\)', // IN(list) |
|
| 1569 | - '\s+NOT IN\s*\(.*\)', // NOT IN (list) |
|
| 1570 | - '\s+LIKE\s+\S.*('.$_les.')?', // LIKE 'expr'[ ESCAPE '%s'] |
|
| 1560 | + '\s*(?:<|>|!)?=\s*', // =, <=, >=, != |
|
| 1561 | + '\s*<>?\s*', // <, <> |
|
| 1562 | + '\s*>\s*', // > |
|
| 1563 | + '\s+IS NULL', // IS NULL |
|
| 1564 | + '\s+IS NOT NULL', // IS NOT NULL |
|
| 1565 | + '\s+EXISTS\s*\(.*\)', // EXISTS(sql) |
|
| 1566 | + '\s+NOT EXISTS\s*\(.*\)', // NOT EXISTS(sql) |
|
| 1567 | + '\s+BETWEEN\s+', // BETWEEN value AND value |
|
| 1568 | + '\s+IN\s*\(.*\)', // IN(list) |
|
| 1569 | + '\s+NOT IN\s*\(.*\)', // NOT IN (list) |
|
| 1570 | + '\s+LIKE\s+\S.*('.$_les.')?', // LIKE 'expr'[ ESCAPE '%s'] |
|
| 1571 | 1571 | '\s+NOT LIKE\s+\S.*('.$_les.')?' // NOT LIKE 'expr'[ ESCAPE '%s'] |
| 1572 | 1572 | ); |
| 1573 | 1573 | |
@@ -1735,7 +1735,7 @@ discard block |
||
| 1735 | 1735 | */ |
| 1736 | 1736 | public function display_error($error = '', $swap = '', $native = FALSE) |
| 1737 | 1737 | { |
| 1738 | - $LANG =& load_class('Lang', 'core'); |
|
| 1738 | + $LANG = & load_class('Lang', 'core'); |
|
| 1739 | 1739 | $LANG->load('db'); |
| 1740 | 1740 | |
| 1741 | 1741 | $heading = $LANG->line('db_error_heading'); |
@@ -1773,7 +1773,7 @@ discard block |
||
| 1773 | 1773 | } |
| 1774 | 1774 | } |
| 1775 | 1775 | |
| 1776 | - $error =& load_class('Exceptions', 'core'); |
|
| 1776 | + $error = & load_class('Exceptions', 'core'); |
|
| 1777 | 1777 | echo $error->show_error($heading, $message, 'error_db'); |
| 1778 | 1778 | exit(8); // EXIT_DATABASE |
| 1779 | 1779 | } |
@@ -431,7 +431,7 @@ discard block |
||
| 431 | 431 | // We still don't have a connection? |
| 432 | 432 | if ( ! $this->conn_id) |
| 433 | 433 | { |
| 434 | - error_log('error', 'Unable to connect to the database'); |
|
| 434 | + error_log('error', 'Unable to connect to the database'); |
|
| 435 | 435 | |
| 436 | 436 | if ($this->db_debug) |
| 437 | 437 | { |
@@ -528,7 +528,7 @@ discard block |
||
| 528 | 528 | { |
| 529 | 529 | if (method_exists($this, '_db_set_charset') && ! $this->_db_set_charset($charset)) |
| 530 | 530 | { |
| 531 | - error_log('error', 'Unable to set database connection charset: '.$charset); |
|
| 531 | + error_log('error', 'Unable to set database connection charset: '.$charset); |
|
| 532 | 532 | |
| 533 | 533 | if ($this->db_debug) |
| 534 | 534 | { |
@@ -611,7 +611,7 @@ discard block |
||
| 611 | 611 | { |
| 612 | 612 | if ($sql === '') |
| 613 | 613 | { |
| 614 | - error_log('error', 'Invalid query: '.$sql); |
|
| 614 | + error_log('error', 'Invalid query: '.$sql); |
|
| 615 | 615 | return ($this->db_debug) ? $this->display_error('db_invalid_query') : FALSE; |
| 616 | 616 | } |
| 617 | 617 | elseif ( ! is_bool($return_object)) |
@@ -684,7 +684,7 @@ discard block |
||
| 684 | 684 | $this->trans_complete(); |
| 685 | 685 | if ($trans_depth === $this->_trans_depth) |
| 686 | 686 | { |
| 687 | - error_log('error', 'Database: Failure during an automated transaction commit/rollback!'); |
|
| 687 | + error_log('error', 'Database: Failure during an automated transaction commit/rollback!'); |
|
| 688 | 688 | break; |
| 689 | 689 | } |
| 690 | 690 | } |
@@ -613,8 +613,7 @@ discard block |
||
| 613 | 613 | { |
| 614 | 614 | error_log('error', 'Invalid query: '.$sql); |
| 615 | 615 | return ($this->db_debug) ? $this->display_error('db_invalid_query') : FALSE; |
| 616 | - } |
|
| 617 | - elseif ( ! is_bool($return_object)) |
|
| 616 | + } elseif ( ! is_bool($return_object)) |
|
| 618 | 617 | { |
| 619 | 618 | $return_object = ! $this->is_write_type($sql); |
| 620 | 619 | } |
@@ -979,13 +978,11 @@ discard block |
||
| 979 | 978 | if (empty($this->bind_marker) OR strpos($sql, $this->bind_marker) === FALSE) |
| 980 | 979 | { |
| 981 | 980 | return $sql; |
| 982 | - } |
|
| 983 | - elseif ( ! is_array($binds)) |
|
| 981 | + } elseif ( ! is_array($binds)) |
|
| 984 | 982 | { |
| 985 | 983 | $binds = array($binds); |
| 986 | 984 | $bind_count = 1; |
| 987 | - } |
|
| 988 | - else |
|
| 985 | + } else |
|
| 989 | 986 | { |
| 990 | 987 | // Make sure we're using numeric keys |
| 991 | 988 | $binds = array_values($binds); |
@@ -1009,8 +1006,7 @@ discard block |
||
| 1009 | 1006 | { |
| 1010 | 1007 | return $sql; |
| 1011 | 1008 | } |
| 1012 | - } |
|
| 1013 | - elseif (($c = preg_match_all('/'.preg_quote($this->bind_marker, '/').'/i', $sql, $matches, PREG_OFFSET_CAPTURE)) !== $bind_count) |
|
| 1009 | + } elseif (($c = preg_match_all('/'.preg_quote($this->bind_marker, '/').'/i', $sql, $matches, PREG_OFFSET_CAPTURE)) !== $bind_count) |
|
| 1014 | 1010 | { |
| 1015 | 1011 | return $sql; |
| 1016 | 1012 | } |
@@ -1097,16 +1093,13 @@ discard block |
||
| 1097 | 1093 | { |
| 1098 | 1094 | $str = array_map(array(&$this, 'escape'), $str); |
| 1099 | 1095 | return $str; |
| 1100 | - } |
|
| 1101 | - elseif (is_string($str) OR (is_object($str) && method_exists($str, '__toString'))) |
|
| 1096 | + } elseif (is_string($str) OR (is_object($str) && method_exists($str, '__toString'))) |
|
| 1102 | 1097 | { |
| 1103 | 1098 | return "'".$this->escape_str($str)."'"; |
| 1104 | - } |
|
| 1105 | - elseif (is_bool($str)) |
|
| 1099 | + } elseif (is_bool($str)) |
|
| 1106 | 1100 | { |
| 1107 | 1101 | return ($str === FALSE) ? 0 : 1; |
| 1108 | - } |
|
| 1109 | - elseif ($str === NULL) |
|
| 1102 | + } elseif ($str === NULL) |
|
| 1110 | 1103 | { |
| 1111 | 1104 | return 'NULL'; |
| 1112 | 1105 | } |
@@ -1257,12 +1250,10 @@ discard block |
||
| 1257 | 1250 | if (isset($row['table_name'])) |
| 1258 | 1251 | { |
| 1259 | 1252 | $key = 'table_name'; |
| 1260 | - } |
|
| 1261 | - elseif (isset($row['TABLE_NAME'])) |
|
| 1253 | + } elseif (isset($row['TABLE_NAME'])) |
|
| 1262 | 1254 | { |
| 1263 | 1255 | $key = 'TABLE_NAME'; |
| 1264 | - } |
|
| 1265 | - else |
|
| 1256 | + } else |
|
| 1266 | 1257 | { |
| 1267 | 1258 | /* We have no other choice but to just get the first element's key. |
| 1268 | 1259 | * Due to array_shift() accepting its argument by reference, if |
@@ -1325,12 +1316,10 @@ discard block |
||
| 1325 | 1316 | if (isset($row['column_name'])) |
| 1326 | 1317 | { |
| 1327 | 1318 | $key = 'column_name'; |
| 1328 | - } |
|
| 1329 | - elseif (isset($row['COLUMN_NAME'])) |
|
| 1319 | + } elseif (isset($row['COLUMN_NAME'])) |
|
| 1330 | 1320 | { |
| 1331 | 1321 | $key = 'COLUMN_NAME'; |
| 1332 | - } |
|
| 1333 | - else |
|
| 1322 | + } else |
|
| 1334 | 1323 | { |
| 1335 | 1324 | // We have no other choice but to just get the first element's key. |
| 1336 | 1325 | $key = key($row); |
@@ -1386,8 +1375,7 @@ discard block |
||
| 1386 | 1375 | if ($this->_escape_char === '' OR empty($item) OR in_array($item, $this->_reserved_identifiers)) |
| 1387 | 1376 | { |
| 1388 | 1377 | return $item; |
| 1389 | - } |
|
| 1390 | - elseif (is_array($item)) |
|
| 1378 | + } elseif (is_array($item)) |
|
| 1391 | 1379 | { |
| 1392 | 1380 | foreach ($item as $key => $value) |
| 1393 | 1381 | { |
@@ -1414,8 +1402,7 @@ discard block |
||
| 1414 | 1402 | $this->_escape_char[0], |
| 1415 | 1403 | $this->_escape_char[1] |
| 1416 | 1404 | ); |
| 1417 | - } |
|
| 1418 | - else |
|
| 1405 | + } else |
|
| 1419 | 1406 | { |
| 1420 | 1407 | $preg_ec[0] = $preg_ec[1] = preg_quote($this->_escape_char, '/'); |
| 1421 | 1408 | $preg_ec[2] = $preg_ec[3] = $this->_escape_char; |
@@ -1683,8 +1670,7 @@ discard block |
||
| 1683 | 1670 | if ( ! class_exists('CI_DB_Cache', FALSE)) |
| 1684 | 1671 | { |
| 1685 | 1672 | require_once(BASEPATH.'database/DB_cache.php'); |
| 1686 | - } |
|
| 1687 | - elseif (is_object($this->CACHE)) |
|
| 1673 | + } elseif (is_object($this->CACHE)) |
|
| 1688 | 1674 | { |
| 1689 | 1675 | return TRUE; |
| 1690 | 1676 | } |
@@ -1743,8 +1729,7 @@ discard block |
||
| 1743 | 1729 | if ($native === TRUE) |
| 1744 | 1730 | { |
| 1745 | 1731 | $message = (array) $error; |
| 1746 | - } |
|
| 1747 | - else |
|
| 1732 | + } else |
|
| 1748 | 1733 | { |
| 1749 | 1734 | $message = is_array($error) ? $error : array(str_replace('%s', $swap, $LANG->line($error))); |
| 1750 | 1735 | } |
@@ -1847,15 +1832,13 @@ discard block |
||
| 1847 | 1832 | ? substr($item, $offset, 4).$this->escape_identifiers(substr($item, $offset + 4)) |
| 1848 | 1833 | : substr($item, $offset); |
| 1849 | 1834 | $item = substr($item, 0, $offset); |
| 1850 | - } |
|
| 1851 | - elseif ($offset = strrpos($item, ' ')) |
|
| 1835 | + } elseif ($offset = strrpos($item, ' ')) |
|
| 1852 | 1836 | { |
| 1853 | 1837 | $alias = ($protect_identifiers) |
| 1854 | 1838 | ? ' '.$this->escape_identifiers(substr($item, $offset + 1)) |
| 1855 | 1839 | : substr($item, $offset); |
| 1856 | 1840 | $item = substr($item, 0, $offset); |
| 1857 | - } |
|
| 1858 | - else |
|
| 1841 | + } else |
|
| 1859 | 1842 | { |
| 1860 | 1843 | $alias = ''; |
| 1861 | 1844 | } |