Skip to content

Commit b8ff9e2

Browse files
committed
DB PREFIX
DB PREFIX
1 parent 145c428 commit b8ff9e2

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ $obj = new kdbv(array(
8484
'PASS' => '<database_password>',
8585
'PORT' => '<mysql_port>',
8686
'KDBV' => '<kdbv_database_name>' //name of kdbv database
87+
'PREFIX' => '<table prefix>', //table prefix
8788
));
8889
```
8990
> ```<kdbv_database_name>``` is a name of ```kdbv database``` which to be deploy with your application

src/db.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
class db{
66

77
public static $btree = null;
8+
public static $notation = array();
89

910
public static function init($db){
1011

@@ -14,19 +15,33 @@ public static function init($db){
1415

1516
public static function set($key,$value){
1617

18+
if(!empty(self::$notation['|:prefix:|'])){
19+
$value = json_decode(strtr(json_encode($value),array_flip(self::$notation)),1);
20+
$key = json_decode(strtr(json_encode($key),array_flip(self::$notation)),1);
21+
}
22+
1723
self::$btree->set($key,gzdeflate(serialize($value), 9));
1824

1925
}
2026

2127
public static function get($key){
2228

29+
if(!empty(self::$notation['|:prefix:|'])){
30+
$key = json_decode(strtr(json_encode($key),array_flip(self::$notation)),1);
31+
}
32+
2333
$return = self::$btree->get($key);
2434

2535
if(!$return){
2636
return false;
2737
}
2838

29-
return unserialize(gzinflate($return));
39+
$return = unserialize(gzinflate($return));
40+
41+
if(!isset(self::$notation['|:prefix:|'])){
42+
self::$notation['|:prefix:|'] = '';
43+
}
3044

45+
return json_decode(strtr(json_encode($return),self::$notation),1);
3146
}
3247
}

src/kdbv.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@
77
class kdbv extends tabledef{
88

99
function __construct($pdodsn){
10+
11+
db::$notation['|:prefix:|'] = $pdodsn['PREFIX'];
12+
1013
$this->init($pdodsn);
1114
}
1215

1316
function init($pdodsn){
1417

1518
$this->pdodsn = $pdodsn;
1619

20+
1721
$charset = 'utf8mb4';
1822

1923
$dsn = "mysql:host={$pdodsn['HOST']};port={$pdodsn['PORT']};dbname={$pdodsn['DATABASE']};charset=$charset";

src/table.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ class tabledef{
1111
public $pdodsn = null;
1212
public $sql = array();
1313
public $key = false;
14-
public $extra = false;
1514

1615
function setTables(){
1716

@@ -264,13 +263,13 @@ function generateCollation($collation){
264263
return '';
265264
}
266265

267-
function generateDefaultCommand($definitions){
268-
269-
if($this->extra){
270-
if($definitions['Extra'] == 'auto_increment'){
271-
return "AUTO_INCREMENT";
272-
}
266+
function generateDefault($definitions){
267+
if($definitions['Extra'] != 'auto_increment'){
268+
return $definitions['Extra'];
273269
}
270+
}
271+
272+
function generateDefaultCommand($definitions){
274273

275274
if (in_array($definitions['Default'], array('CURRENT_TIMESTAMP', 'CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'))) {
276275
return "DEFAULT {$definitions['Default']}";
@@ -314,9 +313,8 @@ function create_table($ctable){
314313
$entries = array();
315314
$primaryKey = array();
316315
$keys = array();
317-
//$this->extra = true;
318316
foreach (db::get($ctable) as $columnName => $definitions) {
319-
$entries[] = '`' . $columnName . '` ' . $definitions['Type'] . ' '. $this->generateCollation($definitions['Collation']) .' ' . $this->generateNullCommand($definitions['Null']) . ' ' . $this->generateDefaultCommand($definitions) . ' ' . $this->generateDefaultComment($definitions);
317+
$entries[] = '`' . $columnName . '` ' . $definitions['Type'] . ' '. $this->generateCollation($definitions['Collation']) .' ' . $this->generateNullCommand($definitions['Null']) . ' ' . $this->generateDefaultCommand($definitions) . ' '. $this->generateDefault($definitions) .' ' . $this->generateDefaultComment($definitions);
320318

321319
if ($definitions['Key'] == 'PRI') {
322320
$primaryKey[] = $columnName;
@@ -326,7 +324,7 @@ function create_table($ctable){
326324
$keys[] = $columnName;
327325
}
328326
}
329-
//$this->extra = false;
327+
330328
/*
331329
if (count($primaryKey) > 0) {
332330
$entries[] = 'PRIMARY KEY (`' . implode('`,`', $primaryKey) . '`)';

0 commit comments

Comments
 (0)