Skip to content

Commit a8b8c8d

Browse files
committed
Allow prefix configuration out of constructor
1 parent ea35ad4 commit a8b8c8d

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

MysqliDb.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class MysqliDb
2424
*
2525
* @var string
2626
*/
27-
public static $prefix;
27+
public static $prefix = '';
2828
/**
2929
* MySQLi instance
3030
*
@@ -167,7 +167,8 @@ public function __construct($host = NULL, $username = NULL, $password = NULL, $d
167167
$this->isSubQuery = true;
168168
return;
169169
}
170-
$this->setPrefix();
170+
if (isset ($prefix))
171+
$this->setPrefix ($prefix);
171172
self::$_instance = $this;
172173
}
173174

tests/mysqliDbTests.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
require_once ("../MysqliDb.php");
33
error_reporting(E_ALL);
44

5+
$prefix = 't_';
56
$db = new Mysqlidb('localhost', 'root', '', 'testdb');
67
if(!$db) die("Database error");
78

@@ -12,13 +13,11 @@
1213
'host' => 'localhost',
1314
'username' => 'root',
1415
'password' => '',
15-
'db'=> 'testdb',
16+
'db' => 'testdb',
17+
'prefix' => $prefix,
1618
'charset' => null));
1719
if(!$db) die("Database error");
1820

19-
20-
$prefix = 't_';
21-
$db->setPrefix($prefix);
2221
$db->setTrace(true);
2322

2423
$tables = Array (
@@ -117,7 +116,6 @@ function createTable ($name, $data) {
117116
exit;
118117
}
119118

120-
$str = $db->escape ("te'st");
121119
// insert test with autoincrement
122120
foreach ($data as $name => $datas) {
123121
foreach ($datas as $d) {

0 commit comments

Comments
 (0)