@@ -85,6 +85,7 @@ private static function getInstance($key = false)
85
85
$ instance = new PDO ('mysql:host= ' . self ::$ connections [self ::$ connectionName ]['HOST ' ] . ";dbname= " . self ::$ connections [self ::$ connectionName ]['NAME ' ] . "; " , self ::$ connections [self ::$ connectionName ]['USER ' ], self ::$ connections [self ::$ connectionName ]['PASSWORD ' ]);
86
86
if ($ instance ) {
87
87
$ instance ->setAttribute (PDO ::ATTR_EMULATE_PREPARES , false );
88
+ $ instance ->setAttribute (PDO ::ATTR_ERRMODE , PDO ::ERRMODE_EXCEPTION );
88
89
self ::updateTotalRequests ();
89
90
return $ instance ;
90
91
} else {
@@ -269,6 +270,9 @@ public static function empty($query)
269
270
}
270
271
}
271
272
if ($ query instanceof dbObject) {
273
+ if (is_bool ($ query ->getInstance ())) {
274
+ return true ;
275
+ }
272
276
return ($ query ->getInstance ()->rowCount () == 0 );
273
277
}
274
278
}
@@ -580,7 +584,7 @@ private static function fixDataCollumns($data, $table, &$newData = array(), $mod
580
584
foreach ($ collumns as $ collumn ) {
581
585
if ($ collumn ['Key ' ] == "PRI " && $ collumn ['Extra ' ] == "" ) {
582
586
$ id = self ::fetch (self ::query ("SELECT $ collumn [Field] FROM $ table ORDER BY $ collumn [Field] DESC LIMIT 1 " ));
583
- $ newData [$ collumn ['Field ' ]] = ++$ id [' id ' ];
587
+ $ newData [$ collumn ['Field ' ]] = ++$ id [$ collumn [ ' Field ' ] ];
584
588
} else if ($ collumn ['Key ' ] == "PRI " && $ collumn ['Extra ' ] !== "" ) {
585
589
unset($ newData [$ collumn ['Field ' ]]);
586
590
}
@@ -593,25 +597,22 @@ private static function fixDataCollumns($data, $table, &$newData = array(), $mod
593
597
} else {
594
598
if (preg_match ("/int/ " , $ collumn ['Type ' ]) && !isset ($ newData [$ collumn ['Field ' ]]) && $ collumn ['Extra ' ] == "" ) {
595
599
$ newData [$ collumn ['Field ' ]] = 0 ;
596
- }
597
- if (preg_match ("/char|text/ " , $ collumn ['Type ' ])) {
600
+ } else if (preg_match ("/char|text/ " , $ collumn ['Type ' ])) {
598
601
$ newData [$ collumn ['Field ' ]] = "" ;
599
- }
600
- if (preg_match ("/date|time|year/ " , $ collumn ['Type ' ])) {
602
+ } else if (preg_match ("/date|time|year/ " , $ collumn ['Type ' ])) {
601
603
if ($ collumn ['Type ' ] == "datetime " ) {
602
- $ newData [$ collumn ['Field ' ]] = " 0000-00-00 00:00:00 " ;
603
- }
604
+ $ newData [$ collumn ['Field ' ]] = self :: dateTime () ;
605
+ } else
604
606
if ($ collumn ['Type ' ] == "date " ) {
605
- $ newData [$ collumn ['Field ' ]] = " 0000-00-00 " ;
606
- }
607
+ $ newData [$ collumn ['Field ' ]] = self :: date () ;
608
+ } else
607
609
if ($ collumn ['Type ' ] == "year " ) {
608
- $ newData [$ collumn ['Field ' ]] = " 0000 " ;
609
- }
610
+ $ newData [$ collumn ['Field ' ]] = self :: date ( " Y " ) ;
611
+ } else
610
612
if ($ collumn ['Type ' ] == "timestamp " ) {
611
613
$ newData [$ collumn ['Field ' ]] = time ();
612
614
}
613
- }
614
- if (preg_match ('/enum|set/ ' , $ collumn ['Type ' ])) {
615
+ } else if (preg_match ('/enum|set/ ' , $ collumn ['Type ' ])) {
615
616
preg_match ("/(?:[set|enum])(?:\()(.*?)(?:\))/ " , $ collumn ['Type ' ], $ matches );
616
617
$ values = explode (", " , $ matches [1 ]);
617
618
$ value = substr ($ values [0 ], 1 );
@@ -710,12 +711,11 @@ public static function insert($data, $table, $additional = array())
710
711
$ stmnt ->execute ();
711
712
self ::updateTotalRequests ();
712
713
self ::$ id = $ instance ->lastInsertId ();
713
- unset($ stmnt , $ instance );
714
- return true ;
714
+ return (self ::$ id != 0 );
715
715
}
716
716
return false ;
717
717
} catch (Error $ e ) {
718
- throw (" An error ocurred: " . $ e );
718
+ throw ($ e );
719
719
return false ;
720
720
}
721
721
}
@@ -757,7 +757,6 @@ public static function update($data, $table, $rules = array(), $additional = arr
757
757
foreach ($ newData as $ key => $ value ) {
758
758
self ::set ($ stmnt , $ key , $ value );
759
759
}
760
-
761
760
if (!empty ($ rules )) {
762
761
foreach ($ rules as $ key => $ value ) {
763
762
self ::set ($ stmnt , "rule_ " . $ key , $ value );
@@ -809,6 +808,7 @@ public static function delete($table, $rules = array())
809
808
}
810
809
811
810
/**
811
+ * TODO
812
812
* @param string Search term to get all words
813
813
* @return array Array containing all words and combinations with the given words
814
814
*/
0 commit comments