77 */
88namespace Wepesi \App ;
99use Exception ;
10- use PDO ;
1110use Wepesi \App \Traits \BuildQuery ;
1211
1312class DB
@@ -18,13 +17,13 @@ class DB
1817 private ?string $ _error ;
1918 private array $ _results ;
2019 private int $ _lastID ;
21- private PDO $ pdo ;
20+ private \ PDO $ pdo ;
2221 private string $ _action ="" ;
2322 private int $ _count ;
2423 private array $ option =[
25- PDO ::MYSQL_ATTR_INIT_COMMAND =>"SET NAMES utf8 " ,
26- PDO ::ATTR_EMULATE_PREPARES =>false ,
27- PDO ::ATTR_ERRMODE =>PDO ::ERRMODE_EXCEPTION
24+ \ PDO ::MYSQL_ATTR_INIT_COMMAND =>"SET NAMES utf8 " ,
25+ \ PDO ::ATTR_EMULATE_PREPARES =>false ,
26+ \ PDO ::ATTR_ERRMODE =>\ PDO ::ERRMODE_EXCEPTION
2827 ] ;
2928 use BuildQuery;
3029 private function __construct (string $ host ="" ,string $ db_name ="" ,string $ user_name ="" ,string $ password ="" )
@@ -35,7 +34,7 @@ private function __construct(string $host="",string $db_name="",string $user_nam
3534 $ this ->_lastID = -1 ;
3635 $ this ->_count = 0 ;
3736 //
38- $ this ->pdo = new PDO ("mysql:host= " . $ host . ";dbname= " . $ db_name .";charset=utf8mb4 " , $ user_name ,$ password ,$ this ->option );
37+ $ this ->pdo = new \ PDO ("mysql:host= " . $ host . ";dbname= " . $ db_name .";charset=utf8mb4 " , $ user_name ,$ password ,$ this ->option );
3938 } catch (\PDOException $ ex ) {
4039 echo $ ex ->getMessage ();
4140 die ();
@@ -143,7 +142,7 @@ function query($sql, array $params = []): DB
143142 $ this ->_results = $ q ['result ' ];
144143 $ this ->_count = $ q ['count ' ];
145144 $ this ->_error = $ q ['error ' ];
146- $ this ->_lastID = $ q ['lastID ' ];
145+ $ this ->_lastID = $ q ['lastID ' ]??- 1 ;
147146
148147 return $ this ;
149148 }
@@ -154,7 +153,7 @@ function query($sql, array $params = []): DB
154153 function lastId (): int
155154 {
156155 if (isset ($ this ->query_transaction ) && method_exists ($ this ->query_transaction , 'lastId ' )) {
157- $ this ->_count = $ this ->query_transaction ->lastId ();
156+ $ this ->_lastID = $ this ->query_transaction ->lastId ();
158157 }
159158 return $ this ->_lastID ;
160159 }
0 commit comments