55use Kir \MySQL \Builder \Exception ;
66use Kir \MySQL \Database ;
77use Kir \MySQL \Tools \AliasRegistry ;
8- use PDO ;
9- use PDOStatement ;
10- use Psr \Log \LoggerInterface ;
11- use Psr \Log \NullLogger ;
128use UnexpectedValueException ;
139use Kir \MySQL \Builder \RunnableSelect ;
1410
@@ -31,22 +27,12 @@ class MySQL implements Database {
3127 * @var int
3228 */
3329 private $ transactionLevel = 0 ;
34- /**
35- * @var LoggerInterface
36- */
37- private $ logger ;
3830
3931 /**
40- * @param PDO $pdo
41- * @param LoggerInterface $logger
32+ * @param \PDO $pdo
4233 */
43- public function __construct (PDO $ pdo , LoggerInterface $ logger = null ) {
44- if ($ logger === null ) {
45- $ logger = new NullLogger ();
46- }
47-
34+ public function __construct (\PDO $ pdo ) {
4835 $ this ->pdo = $ pdo ;
49- $ this ->logger = $ logger ;
5036 $ this ->aliasRegistry = new AliasRegistry ();
5137 }
5238
@@ -60,13 +46,10 @@ public function getAliasRegistry() {
6046 /**
6147 * @param string $query
6248 * @throws Exception
63- * @return PDOStatement
49+ * @return \ PDOStatement
6450 */
6551 public function query ($ query ) {
66- $ this ->logger ->info ($ query );
67- $ timer = microtime (true );
6852 $ stmt = $ this ->pdo ->query ($ query );
69- $ this ->logger ->debug (sprintf ("Last query duration: %0.5f sec. " , microtime (true ) - $ timer ));
7053 if (!$ stmt ) {
7154 throw new Exception ("Could not execute statement: \n{$ query }" );
7255 }
@@ -76,10 +59,9 @@ public function query($query) {
7659 /**
7760 * @param string $query
7861 * @throws Exception
79- * @return PDOStatement
62+ * @return \ PDOStatement
8063 */
8164 public function prepare ($ query ) {
82- $ this ->logger ->info ("PREPARE: {$ query }" );
8365 $ stmt = $ this ->pdo ->prepare ($ query );
8466 if (!$ stmt ) {
8567 throw new Exception ("Could not execute statement: \n{$ query }" );
@@ -93,11 +75,8 @@ public function prepare($query) {
9375 * @return int
9476 */
9577 public function exec ($ query , array $ params = array ()) {
96- $ this ->logger ->info ($ query );
97- $ timer = microtime (true );
9878 $ stmt = $ this ->pdo ->prepare ($ query );
9979 $ stmt ->execute ($ params );
100- $ this ->logger ->debug (sprintf ("Last query duration: %0.5f sec. " , microtime (true ) - $ timer ));
10180 $ result = $ stmt ->rowCount ();
10281 $ stmt ->closeCursor ();
10382 return $ result ;
@@ -115,12 +94,12 @@ public function getLastInsertId() {
11594 * @return array
11695 */
11796 public function getTableFields ($ table ) {
97+ $ table = $ this ->select ()->aliasReplacer ()->replace ($ table );
11898 if (array_key_exists ($ table , self ::$ tableFields )) {
11999 return self ::$ tableFields [$ table ];
120100 }
121101 $ stmt = $ this ->pdo ->query ("DESCRIBE {$ table }" );
122- $ stmt ->execute ();
123- $ rows = $ stmt ->fetchAll (PDO ::FETCH_ASSOC );
102+ $ rows = $ stmt ->fetchAll (\PDO ::FETCH_ASSOC );
124103 self ::$ tableFields [$ table ] = array_map (function ($ row ) { return $ row ['Field ' ]; }, $ rows );
125104 $ stmt ->closeCursor ();
126105 return self ::$ tableFields [$ table ];
0 commit comments