· 4 years ago · Jun 21, 2021, 04:48 PM
1Skip to content
2Why GitHub?
3Team
4Enterprise
5Explore
6Marketplace
7Pricing
8Search
9
10Sign in
11Sign up
12vietbur
13/
14exDBase
1512
16Code
17Issues
181
19Pull requests
20Actions
21Projects
22Wiki
23Security
24Insights
25Merge pull request #3 from Warmbellycat/master
26Немного доработок
27 master (#3)
28@vietbur
29vietbur committed on 27 Aug 2018
302 parents 62627ef + 11170dd commit 6b4a230bfbf2c003c73228feac5792b6475a5215
31Showing with 304 additions and 257 deletions.
32 561 exdbase.php
33@@ -4,9 +4,9 @@ class exDBase
34{
35 private $DB = false;
36 private $limit = '';
37 public $error='';
38 public $query='';
39
40 public $error = '';
41 public $query = '';
42
43 /**
44 * Инициирует новый объект класса exDBase и присоединяется к базе данных MySQL
45 * все параметры стандартные как для создания нового объекта mysqli
46@@ -20,10 +20,10 @@ class exDBase
47 * @param boolean $port
48 * @param boolean $socket
49 */
50 public function __construct ($host, $username, $passwd, $dbname = "", $utf = true, $port = false, $socket = false)
51 {
52 $this->open ($host, $username, $passwd, $dbname, $utf, $port, $socket);
53 }
54 public function __construct($host, $username, $passwd, $dbname = "", $utf = true, $port = false, $socket = false)
55 {
56 $this->open($host, $username, $passwd, $dbname, $utf, $port, $socket);
57 }
58
59 /**
60 * Создает новое подключение к базе данных MySQL, предварительно закрывая старое подключение, если оно открыто.
61@@ -37,90 +37,90 @@ public function __construct ($host, $username, $passwd, $dbname = "", $utf = tru
62 * @param boolean $utf
63 * @param boolean $port
64 * @param boolean $socket
65 * @return void
66 * @return bool
67 */
68 public function open ($host, $username, $passwd, $dbname = "", $utf = true, $port = false, $socket = false)
69 public function open($host, $username, $passwd, $dbname = "", $utf = true, $port = false, $socket = false)
70 {
71 if ($this->DB)
72 if ($this->DB) {
73 $this->close();
74 }
75 $DB = new mysqli ($host, $username, $passwd, $dbname, $port, $socket);
76 if ($DB->connect_error)
77 {
78 $this->error = $DB->connect_error;
79 if ($DB->connect_error) {
80 $this->error = $DB->connect_error;
81 return false;
82 }
83 $this->DB = $DB;
84 if ($utf)
85 {
86 if ($utf) {
87 $this->DB->set_charset('utf8');
88 $this->DB->query ("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8', collation_connection = 'utf8_general_ci'");
89 $this->DB->query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8', collation_connection = 'utf8_general_ci'");
90 }
91 return true;
92 }
93
94
95 /**
96 * Если имеется установленное соединение с базой MySQL, то закрывает его
97 */
98 public function close ()
99 public function close()
100 {
101 if ($this->DB)
102 if ($this->DB) {
103 $this->DB->close();
104 }
105 $this->DB = false;
106 $this->error = '';
107 $this->query = '';
108 }
109
110
111 /**
112 * Вспомогательная функция. Парсит знаки сравнения для параметра WHERE
113 *
114 * @param string $value
115 * @return void
116 * @return array|bool
117 */
118 public function checkSign ($value)
119 public function checkSign($value)
120 {
121 $signs = array (">=", "<=", "<>", ">", "<", "=", "!=");
122 $value = trim ($value);
123 $signs = array(">=", "<=", "<>", ">", "<", "=", "!=");
124 $value = trim($value);
125 $result = false;
126 if (strpos ($value, '(') !== false)
127 if (strpos($value, '(') !== false) {
128 $result['open_bracket'] = '(';
129 elseif (strpos ($value, ')') !== false)
130 } elseif (strpos($value, ')') !== false) {
131 $result['close_bracket'] = ')';
132 if (strpos ($value, '||') !== false)
133 }
134 if (strpos($value, '||') !== false) {
135 $result['glue'] = ' OR ';
136 $value = str_replace (array ('(', ')', '||'), '', $value);
137 foreach ($signs as $s)
138 {
139 if (strpos ($value, $s) === 0)
140 {
141 $result['value'] = substr ($value, strlen ($s));
142 }
143 $value = str_replace(array('(', ')', '||'), '', $value);
144 foreach ($signs as $s) {
145 if (strpos($value, $s) === 0) {
146 $result['value'] = substr($value, strlen($s));
147 $result['prefix'] = $s;
148 break;
149 }
150 }
151 if (!$result['prefix'])
152 {
153 if (!$result['prefix']) {
154 $result['value'] = $value;
155 $result['prefix'] = '';
156 }
157 return $result;
158 }
159
160 /**
161 * Вспомогательная функция.
162 * Вспомогательная функция.
163 * Добавляет одинарные (или двойные если $double=true) кавычки в начале и в конце строки, если $value является строкой
164 *
165 * @param string $value
166 * @param boolean $double
167 * @return void
168 * @return string|integer|double|bool
169 */
170 protected function quoted ($value, $double = false)
171 protected function quoted($value, $double = false)
172 {
173 if (!is_string($value))
174 if (!is_string($value)) {
175 return $value;
176 elseif ($double)
177 } elseif ($double) {
178 return '"' . $value . '"';
179 else
180 } else {
181 return "'" . $value . "'";
182 }
183 }
184
185 /**
186@@ -129,103 +129,107 @@ protected function quoted ($value, $double = false)
187 *
188 * @param string $value
189 * @param boolean $escape
190 * @return void
191 * @return string|integer|double|bool
192 */
193 protected function escape($value, $escape = true)
194 {
195 if (!$escape )
196 if (!$escape) {
197 return $value;
198 }
199 // не строковые значения, а также строки в формате JSON не экранируются
200 if (!is_string ($value) || is_object(json_decode($value)) || is_array(json_decode($value)))
201 if (!is_string($value) || is_object(json_decode($value)) || is_array(json_decode($value))) {
202 return $value;
203 if ($this->DB)
204 }
205 if ($this->DB) {
206 return $this->DB->real_escape_string($value);
207 else
208 return str_replace(array("'",'"'), '', $value);
209 } else {
210 return str_replace(array("'", '"'), '', $value);
211 }
212 }
213
214
215 /**
216 * Устанавливает флаг ошибки в случае, если в запросе не определено имя таблицы
217 *
218 * @return void
219 * @return bool
220 */
221 protected function noTable ()
222 protected function noTable()
223 {
224 $this->error = "No table specified";
225 return false;
226 }
227
228
229 /**
230 * Устанавливает флаг ошибки в случае, если в запросе отсутствуют необходимые поля данных или они ошибочны
231 *
232 * @return void
233 * @return bool
234 */
235 protected function noData ()
236 protected function noData()
237 {
238 $this->error = "No fields/data specified";
239 return false;
240 }
241
242
243 /**
244 * Устанавливает флаг ошибки при запросе в случае, если база данных не открыта
245 *
246 * @return void
247 * @return bool
248 */
249 protected function noDB ()
250 protected function noDB()
251 {
252 $this->error = "No database open";
253 return false;
254 }
255
256
257 /**
258 * Выполняет запрос $qry в текущую открытую базу MySQL, возвращает его результат или false в случае неудачи
259 *
260 * @param string $qry
261 * @return void
262 * @return object|bool
263 */
264 function query ($qry)
265 function query($qry)
266 {
267 if ($this->DB)
268 {
269 $result = $this->DB->query ($qry);
270 if ($this->DB) {
271 $result = $this->DB->query($qry);
272 $this->error = $this->DB->error;
273 $this->query = $qry;
274 return $result;
275 } else {
276 return $this->noDB();
277 }
278 else return $this->noDB();
279 }
280
281
282 /**
283 * Вспомогательная функция
284 * Разбирает набор параметров в строку, алгоритм зависит от параметра $type
285 * $type = 0 - тип SELECT WHERE, результат в виде FIELD1='value1' AND/OR FIELD2>= value2
286 * $type = 1 - тип INSERT, результат в виде (FIELD1, FIELD2) ('value1', value2)
287 * $type = 2 - тип UPDATE, результат в виде "FIELD1=value1, FIELD2='value2'"
288 * $type = 3 - тип поля ORDER BY, результат в виде "FIELD1 value1, FIELD2 value2"
289 * $type = 2 - тип UPDATE, результат в виде "FIELD1=value1, FIELD2='value2'"
290 * $type = 3 - тип поля ORDER BY, результат в виде "FIELD1 value1, FIELD2 value2"
291 * $type = 4 - обычная разворотка, результат в виде "value1, value2, value3"
292 *
293 * @param $fields
294 * @param integer $type
295 * @return void
296 * @return string|bool
297 */
298 public function parse ($fields, $type = 0)
299 {
300 if (is_string($fields))
301 public function parse($fields, $type = 0)
302 {
303 if (is_string($fields)) {
304 return $fields;
305 elseif (empty($fields) || !is_array ($fields))
306 } elseif (empty($fields) || !is_array($fields)) {
307 return false;
308 }
309 // экранируем значения и добавляем кавычки по необходимости
310 foreach ($fields as $key => $value)
311 {
312 $fields[$key] = $this->escape ($value);
313 if ($type < 3)
314 // для SELECT WHERE и для INSERT/UPDATE заключаем строки в кавычки
315 foreach ($fields as $key => $value) {
316 $fields[$key] = $this->escape($value);
317 if ($type < 3) // для SELECT WHERE и для INSERT/UPDATE заключаем строки в кавычки
318 {
319 $fields[$key] = $this->quoted($fields[$key]);
320 }
321 }
322 switch ($type)
323 {
324 $result = [];
325 switch ($type) {
326 case 1:
327 $result['keys'] = implode(", ", array_keys ($fields));
328 $result['keys'] = implode(", ", array_keys($fields));
329 $result['values'] = implode(", ", $fields);
330 break;
331 case 4:
332@@ -235,36 +239,46 @@ public function parse ($fields, $type = 0)
333 case 2:
334 case 3:
335 $result = '';
336 $glues = array ('0' => array ('=', ' AND '), '2' => array ('=', ', '), '3' => array (' ', ', '));
337 foreach ($fields as $key => $value)
338 {
339 $key = trim ($key);
340 $glues = array('0' => array('=', ' AND '), '2' => array('=', ', '), '3' => array(' ', ', '));
341 foreach ($fields as $key => $value) {
342 $key = trim($key);
343 $glue = $glues[$type][1];
344 $res = [];
345 if (!$type)
346 {
347 $res = $this->checkSign ($key);
348 if (!$type) {
349 $res = $this->checkSign($key);
350 $key = $res['value'];
351 if ($res['glue'])
352 // у ключа стоит модификатор OR
353 if ($res['glue']) // у ключа стоит модификатор OR
354 {
355 $glue = $res['glue'];
356 }
357 }
358 if (!$res['prefix']) {
359 $res['prefix'] = $glues[$type][0];
360 }
361 if (!$result) {
362 $glue = '';
363 }
364 if (!$res['prefix']) $res['prefix'] = $glues[$type][0];
365 if (!$result) $glue = '';
366 $result .= $glue . $res['open_bracket'] . $key . $res['prefix'] . $value . $res['close_bracket'];
367 }
368 }
369 return $result;
370 }
371
372 public function setLimit ($limit)
373 /**
374 * Метод задаёт лимит для запросов
375 * @param integer $limit
376 *
377 * @return void
378 */
379 public function setLimit($limit)
380 {
381 if (!$limit)
382 if (!$limit) {
383 $this->limit = '';
384 else
385 $this->limit = " LIMIT " . $limit;
386 } else {
387 $this->limit = " LIMIT " . $limit;
388 }
389 }
390
391
392 /**
393 * Внутренняя функция. Используйте fetchFirst или fetchArray
394 * Метод для выбора значений из таблицы, возвращает ссылку на массив данных как в mysqli
395@@ -277,44 +291,46 @@ public function setLimit ($limit)
396 * @param boolean $where
397 * @param string $fields
398 * @param boolean $order
399 * @return void
400 * @return object|bool
401 */
402 public function select ($table, $where = false, $fields = '*', $order = false)
403 public function select($table, $where = false, $fields = '*', $order = false)
404 {
405 $result = false;
406 $fields = $this->parse ($fields, 4);
407 $table = $this->escape ($table);
408 $where = $this->parse ($where);
409 if ($where)
410 $fields = $this->parse($fields, 4);
411 $table = $this->escape($table);
412 $where = $this->parse($where);
413 if ($where) {
414 $where = "WHERE $where";
415 $order = $this->parse ($order, 3);
416 if ($order)
417 $order = "ORDER BY $order";
418 if (!$table)
419 }
420 $order = $this->parse($order, 3);
421 if ($order) {
422 $order = "ORDER BY $order";
423 }
424 if (!$table) {
425 return $this->noTable();
426 if (!$fields)
427 }
428 if (!$fields) {
429 $fields = '*';
430 $qry = "SELECT $fields FROM $table $where $order $this->limit";
431 }
432 $qry = "SELECT " . $fields . " FROM " . $table . " " . $where . " " . $order . " " . $this->limit;
433 $this->limit = '';
434 return $this->query ($qry);
435 return $this->query($qry);
436 }
437
438
439 /**
440 * То же самое, что метод select, но выбор только первого элемента, возвращает асссоциативный массив для первой записи
441 *
442 * @param string $table
443 * @param boolean $where
444 * @param string $fields
445 * @param boolean $order
446 * @return void
447 * @return bool|array
448 */
449 function fetchFirst ($table, $where = false, $fields = '*', $order = false)
450 function fetchFirst($table, $where = false, $fields = '*', $order = false)
451 {
452 $result = false;
453 if ($res = $this->select($table, $where, $fields, $order))
454 {
455 if ($res = $this->select($table, $where, $fields, $order)) {
456 $result = $res->fetch_assoc();
457 }
458 }
459 return $result;
460 }
461
462@@ -325,15 +341,17 @@ function fetchFirst ($table, $where = false, $fields = '*', $order = false)
463 * @param boolean $where
464 * @param string $fields
465 * @param boolean $order
466 *
467 * @return bool|array
468 */
469 function fetchArray ($table, $where = false, $fields = '*', $order = false)
470 function fetchArray($table, $where = false, $fields = '*', $order = false)
471 {
472 $result = false;
473 if ($res = $this->select($table, $where, $fields, $order))
474 {
475 while ($rec = $res->fetch_assoc())
476 $result[] = $rec;
477 }
478 if ($res = $this->select($table, $where, $fields, $order)) {
479 while ($rec = $res->fetch_assoc()) {
480 $result[] = $rec;
481 }
482 }
483 return $result;
484 }
485
486@@ -343,35 +361,38 @@ function fetchArray ($table, $where = false, $fields = '*', $order = false)
487 * @param string $table
488 * @param boolean $where
489 * @param boolean $order
490 * @return array
491 * @return array|bool
492 */
493 function fetchObject ($table, $where = false, $order = false)
494 function fetchObject($table, $where = false, $order = false)
495 {
496 $result = false;
497 if ($res = $this->select($table, $where, '*', $order))
498 {
499 while ($rec = $res->fetch_object())
500 $result[] = $rec;
501 $res->free();
502 }
503 if ($res = $this->select($table, $where, '*', $order)) {
504 while ($rec = $res->fetch_object()) {
505 $result[] = $rec;
506 }
507 $res->free();
508 }
509 return $result;
510 }
511
512
513 /**
514 * Выбирает из результатов запроса только идентификаторы, по умолчанию поле ID, но можно задать в переменной $id и другое имя поля
515 *
516 * @param string $table
517 * @param boolean $where
518 * @param string $id
519 * @param boolean $order
520 *
521 * @return bool|array
522 */
523 function fetchIDs ($table, $where = false, $id="ID", $order = false)
524 function fetchIDs($table, $where = false, $id = "ID", $order = false)
525 {
526 $result = false;
527 if ($res = $this->select($table, $where, $id, $order))
528 {
529 while ($rec = $res->fetch_assoc())
530 $result[] = $rec [$id];
531 }
532 if ($res = $this->select($table, $where, $id, $order)) {
533 while ($rec = $res->fetch_assoc()) {
534 $result[] = $rec [$id];
535 }
536 }
537 return $result;
538 }
539
540@@ -381,191 +402,217 @@ function fetchIDs ($table, $where = false, $id="ID", $order = false)
541 * @param string $table
542 * @param boolean $where
543 * @param boolean $fields
544 *
545 * @return bool|object
546 */
547 function update ($table, $where = false, $fields = false)
548 function update($table, $where = false, $fields = false)
549 {
550 if (!is_array ($fields))
551 if (!is_array($fields)) {
552 return $this->noData();
553 $table = $this->escape($table);
554 if (!$table)
555 }
556 $table = $this->escape($table);
557 if (!$table) {
558 return $this->noTable();
559 $res = $this->parse ($fields, 2);
560 if ($res)
561 {
562 $where = $this->parse ($where);
563 if ($where)
564 }
565 $res = $this->parse($fields, 2);
566 if ($res) {
567 $where = $this->parse($where);
568 if ($where) {
569 $where = "WHERE $where";
570 }
571 $qry = "UPDATE $table SET $res $where";
572 return $this->query ($qry);
573 }
574 else
575 return $this->query($qry);
576 } else {
577 return $this->noData();
578 }
579
580 }
581 }
582
583 /**
584 * Вставка новой записи в таблицу $table, поля и значения задаются ассоциативным массивом или строкой
585 * Возвращает идентификатор вставленной записи
586 *
587 * @param [type] $table
588 * @param boolean $fields
589 * @param boolean $replace
590 *
591 * @return bool|integer
592 */
593 function insert ($table, $fields = false, $replace = false)
594 {
595 if (!is_array ($fields))
596 function insert($table, $fields = false, $replace = false)
597 {
598 if (!is_array($fields)) {
599 return $this->noData();
600 $res = $this->parse ($fields, 1);
601 if ($res)
602 {
603 $f = $res ['keys'];
604 $v = $res ['values'];
605 $table = $this->escape($table);
606 if (!$table)
607 }
608 $res = $this->parse($fields, 1);
609 if ($res) {
610 $f = $res ['keys'];
611 $v = $res ['values'];
612 $table = $this->escape($table);
613 if (!$table) {
614 return $this->noTable();
615 if (!$f || !$v)
616 }
617 if (!$f || !$v) {
618 return $this->noData();
619 }
620 $qry = ($replace ? 'REPLACE' : 'INSERT') . " INTO $table ($f) VALUES ($v)";
621 $this->query ($qry);
622 return $this->insertID ();
623 $this->query($qry);
624 return $this->insertID();
625 } else {
626 return $this->noData();
627 }
628 else return $this->noData();
629 }
630
631 }
632
633 /**
634 * Замена существующей записи в таблицу $table, поля и значения задаются ассоциативным массивом или строкой
635 *
636 * @param string $table
637 * @param boolean $fields
638 *
639 * @return bool|integer
640 */
641 function replace ($table, $fields = false)
642 {
643 return $this->insert ($table, $fields, true);
644 }
645 function replace($table, $fields = false)
646 {
647 return $this->insert($table, $fields, true);
648 }
649
650 /**
651 * Возвращает номер последней вставленной записи
652 *
653 * @return int
654 */
655 function insertID ()
656 {
657 return $this->DB->insert_id;
658 }
659 function insertID()
660 {
661 return $this->DB->insert_id;
662 }
663
664 /**
665 * Удаление строки из таблицы $table
666 *
667 * @param string $table
668 * @param boolean $where
669 *
670 * @return bool|object
671 */
672 function delete ($table, $where = false)
673 function delete($table, $where = false)
674 {
675 $table = $this->escape($table);
676 if (!$table)
677 $table = $this->escape($table);
678 if (!$table) {
679 return $this->noTable();
680 $where = $this->parse ($where);
681 if ($where)
682 }
683 $where = $this->parse($where);
684 if ($where) {
685 $where = "WHERE $where";
686 $qry = "DELETE FROM $table $where";
687 return $this->query ($qry);
688 }
689
690 }
691 $qry = "DELETE FROM " . $table . " " . $where;
692 return $this->query($qry);
693 }
694
695 /**
696 * Cоздает новую таблицу с именем $table если она не существует либо если $exists = false
697 * в переменной $fields заданы поля в виде ассоциативного массива. Их тип во вновь создаваемой таблице
698 * в переменной $fields заданы поля в виде ассоциативного массива. Их тип во вновь создаваемой таблице
699 * вычисляется по типу значений. Либо, можно задать типы напрямую если значения имеют строковый вид типа
700 * _VARCHAR(255) или _TINYINT (1), то есть начинаются с символа '_'
701 * $keyPrimary - имя поля первичного ключа
702 * $autoInc - массив полей, которые должны иметь автоинкремент
703 *
704 * @param string $table
705 * @param boolean $fields
706 * @param boolean $defaults
707 * @param boolean $keyPrimary
708 * @param boolean $autoInc
709 * @param array $fields
710 * @param array $defaults
711 * @param string $keyPrimary
712 * @param array $autoInc
713 * @param boolean $exists
714 *
715 * @return bool|object
716 */
717 function createEasy ($table, $fields = false, $defaults = false, $keyPrimary = false, $autoInc = false, $exists = true)
718 {
719 $result = false;
720 if (empty ($fields) or !is_array ($fields))
721 function createEasy(
722 $table,
723 $fields = [],
724 $defaults = [],
725 $keyPrimary = false,
726 $autoInc = [],
727 $exists = true
728 ) {
729 if (empty ($fields) or !is_array($fields)) {
730 return false;
731 else
732 {
733 } else {
734 $str = '';
735 foreach ($fields as $key => $value)
736 {
737 if ($str == '')
738 foreach ($fields as $key => $value) {
739 if ($str == '') {
740 $comma = '';
741 else
742 } else {
743 $comma = ', ';
744 $type = gettype ($value);
745 switch ($type)
746 {
747 case 'boolean':
748 $t = "TINYINT(1)";
749 break;
750 case 'integer':
751 if (abs ($value) < 2147483648)
752 $t = "INT";
753 else
754 $t = "BIGINT";
755 break;
756 case 'double':
757 $t = "DOUBLE";
758 break;
759 case 'string':
760 if (strpos ($value, '_') === 0)
761 $t = substr ($value, 1);
762 else
763 {
764 $len = strlen ($value);
765 if ($len < 256)
766 }
767 $type = gettype($value);
768 switch ($type) {
769 case 'boolean':
770 $t = "TINYINT(1)";
771 break;
772 case 'integer':
773 if (abs($value) < 2147483648) {
774 $t = "INT";
775 } else {
776 $t = "BIGINT";
777 }
778 break;
779 case 'double':
780 $t = "DOUBLE";
781 break;
782 case 'string':
783 if (strpos($value, '_') === 0) {
784 $t = substr($value, 1);
785 } else {
786 $len = strlen($value);
787 if ($len < 256) {
788 $t = "VARCHAR(255)";
789 elseif ($len < 65536)
790 } elseif ($len < 65536) {
791 $t = "TEXT";
792 elseif ($len < 16777216)
793 } elseif ($len < 16777216) {
794 $t = "MEDIUMTEXT";
795 else
796 } else {
797 $t = "LONGTEXT";
798 }
799 }
800 break;
801 default:
802 $t = "VARCHAR(255)";
803 }
804 break;
805 default:
806 $t = "VARCHAR(255)";
807 }
808
809 if (!empty ($defaults [$key]))
810 {
811 if (is_string ($value))
812 $defaults [$key] = "'" . $defaults [$key] . "'";
813 $t .= ' DEFAULT ' . $defaults [$key];
814 }
815 else
816 $t .= ' DEFAULT NULL';
817 if (($key == $keyPrimary) || in_array($key, $autoInc))
818 $t .= ' AUTO_INCREMENT';
819 $key = str_replace(array("'",'"'), '', $key);
820 $str .= "$comma $key $t";
821 if (!empty($defaults [$key])) {
822 if (is_string($value)) {
823 $defaults [$key] = "'" . $defaults [$key] . "'";
824 }
825 $t .= ' DEFAULT ' . $defaults [$key];
826 } else {
827 $t .= ' DEFAULT NULL';
828 }
829 if (($key == $keyPrimary) || in_array($key, $autoInc)) {
830 $t .= ' AUTO_INCREMENT';
831 }
832 $key = str_replace(array("'", '"'), '', $key);
833 $str .= "$comma $key $t";
834 }
835
836 $table = str_replace(array("'",'"'), '', $table);
837 if (empty ($table))
838
839 $table = str_replace(array("'", '"'), '', $table);
840 if (empty ($table)) {
841 return false;
842 if (empty ($str))
843 }
844 if (empty ($str)) {
845 return false;
846 }
847
848 $keyPrimary = str_replace(array("'",'"'), '', $keyPrimary);
849 if ($keyPrimary)
850 $primary = ", PRIMARY KEY ($keyPrimary)";
851 else
852 $primary = '';
853 if ($exists)
854 $exists = " IF NOT EXISTS";
855 else
856 $exists = '';
857 $sql = "CREATE TABLE $exists $table ($str $primary) ENGINE=InnoDB, CHARACTER SET = 'utf8', CONNECTION = 'utf8_general_ci'";
858 $result = $this->DB->query ($sql);
859 }
860 return $result;
861 }
862 $keyPrimary = str_replace(array("'", '"'), '', $keyPrimary);
863 if ($keyPrimary) {
864 $primary = ", PRIMARY KEY ($keyPrimary)";
865 } else {
866 $primary = '';
867 }
868 if ($exists) {
869 $exists = " IF NOT EXISTS";
870 } else {
871 $exists = '';
872 }
873 $sql = "CREATE TABLE " . $exists . " " . $table . " (" . $str . " " . $primary . ") ENGINE=InnoDB, CHARACTER SET = 'utf8', CONNECTION = 'utf8_general_ci'";
874 $result = $this->DB->query($sql);
875 }
876 return $result;
877 }
878}
8790 comments on commit 6b4a230
880Please sign in to comment.
881© 2021 GitHub, Inc.
882Terms
883Privacy
884Security
885Status
886Docs
887Contact GitHub
888Pricing
889API
890Training
891Blog
892About
893