66
77use PhpMyAdmin \ConfigStorage \Features \PdfFeature ;
88use PhpMyAdmin \DatabaseInterface ;
9+ use PhpMyAdmin \Dbal \ResultInterface ;
910use PhpMyAdmin \InternalRelations ;
1011use PhpMyAdmin \RecentFavoriteTable ;
1112use PhpMyAdmin \SqlParser \Parser ;
2930use function implode ;
3031use function in_array ;
3132use function is_array ;
32- use function is_bool ;
3333use function is_scalar ;
3434use function is_string ;
3535use function ksort ;
@@ -69,28 +69,24 @@ public function __construct(DatabaseInterface $dbi)
6969 * @param string $sql the query to execute
7070 * @param bool $show_error whether to display SQL error messages or not
7171 * @param int $options query options
72+ * @psalm-param T $show_error
7273 *
73- * @return mixed|bool the result set, or false if no result set
74+ * @return ResultInterface|false the result set, or false if no result set
75+ * @psalm-return (T is true ? ResultInterface : ResultInterface|false)
76+ *
77+ * @template T as bool
7478 */
7579 public function queryAsControlUser ($ sql , $ show_error = true , $ options = 0 )
7680 {
7781 // Avoid caching of the number of rows affected; for example, this function
7882 // is called for tracking purposes but we want to display the correct number
7983 // of rows affected by the original query, not by the query generated for
8084 // tracking.
81- $ cache_affected_rows = false ;
82-
8385 if ($ show_error ) {
84- $ result = $ this ->dbi ->query ($ sql , DatabaseInterface::CONNECT_CONTROL , $ options , $ cache_affected_rows );
85- } else {
86- $ result = @$ this ->dbi ->tryQuery ($ sql , DatabaseInterface::CONNECT_CONTROL , $ options , $ cache_affected_rows );
87- }
88-
89- if ($ result ) {
90- return $ result ;
86+ return $ this ->dbi ->query ($ sql , DatabaseInterface::CONNECT_CONTROL , $ options , false );
9187 }
9288
93- return false ;
89+ return $ this -> dbi -> tryQuery ( $ sql , DatabaseInterface:: CONNECT_CONTROL , $ options , false ) ;
9490 }
9591
9692 public function getRelationParameters (): RelationParameters
@@ -194,11 +190,11 @@ private function fillRelationParamsWithTableNames(array $relationParams): ?array
194190 $ tabQuery = 'SHOW TABLES FROM '
195191 . Util::backquote ($ GLOBALS ['cfg ' ]['Server ' ]['pmadb ' ]);
196192 $ tableRes = $ this ->queryAsControlUser ($ tabQuery , false , DatabaseInterface::QUERY_STORE );
197- if (is_bool ( $ tableRes) ) {
193+ if ($ tableRes === false ) {
198194 return null ;
199195 }
200196
201- while ($ currTable = @ $ this -> dbi -> fetchRow ($ tableRes )) {
197+ while ($ currTable = $ tableRes -> fetchRow ()) {
202198 if ($ currTable [0 ] == $ GLOBALS ['cfg ' ]['Server ' ]['bookmarktable ' ]) {
203199 $ relationParams ['bookmark ' ] = (string ) $ currTable [0 ];
204200 } elseif ($ currTable [0 ] == $ GLOBALS ['cfg ' ]['Server ' ]['relation ' ]) {
@@ -240,8 +236,6 @@ private function fillRelationParamsWithTableNames(array $relationParams): ?array
240236 }
241237 }
242238
243- $ this ->dbi ->freeResult ($ tableRes );
244-
245239 return $ relationParams ;
246240 }
247241
@@ -395,8 +389,8 @@ public function tryUpgradeTransformations(): bool
395389 . ' WHERE Field IN ( \'' . implode ('\', \'' , $ new_cols ) . '\') ' ;
396390 $ result = $ this ->queryAsControlUser ($ query , false , DatabaseInterface::QUERY_STORE );
397391 if ($ result ) {
398- $ rows = $ this -> dbi -> numRows ($ result );
399- $ this -> dbi -> freeResult ($ result );
392+ $ rows = $ result -> numRows ();
393+ unset ($ result );
400394 // input transformations are present
401395 // no need to upgrade
402396 if ($ rows === 2 ) {
@@ -620,8 +614,8 @@ public function getDbComment(string $db): string
620614 . ' AND column_name = \'(db_comment) \'' ;
621615 $ com_rs = $ this ->queryAsControlUser ($ com_qry , false , DatabaseInterface::QUERY_STORE );
622616
623- if ($ com_rs && $ this -> dbi -> numRows ($ com_rs ) > 0 ) {
624- $ row = $ this -> dbi -> fetchAssoc ($ com_rs );
617+ if ($ com_rs && $ com_rs -> numRows () > 0 ) {
618+ $ row = $ com_rs -> fetchAssoc ();
625619
626620 return (string ) $ row ['comment ' ];
627621 }
@@ -638,7 +632,6 @@ public function getDbComment(string $db): string
638632 public function getDbComments ()
639633 {
640634 $ columnCommentsFeature = $ this ->getRelationParameters ()->columnCommentsFeature ;
641- $ comments = [];
642635
643636 if ($ columnCommentsFeature !== null ) {
644637 // pmadb internal db comment
@@ -648,16 +641,12 @@ public function getDbComments()
648641 . ' WHERE `column_name` = \'(db_comment) \'' ;
649642 $ com_rs = $ this ->queryAsControlUser ($ com_qry , false , DatabaseInterface::QUERY_STORE );
650643
651- if ($ com_rs && $ this ->dbi ->numRows ($ com_rs ) > 0 ) {
652- while ($ row = $ this ->dbi ->fetchAssoc ($ com_rs )) {
653- $ comments [$ row ['db_name ' ]] = $ row ['comment ' ];
654- }
644+ if ($ com_rs && $ com_rs ->numRows () > 0 ) {
645+ return $ com_rs ->fetchAllKeyPair ();
655646 }
656-
657- $ this ->dbi ->freeResult ($ com_rs );
658647 }
659648
660- return $ comments ;
649+ return [] ;
661650 }
662651
663652 /**
@@ -1119,17 +1108,12 @@ public function getForeignData(
11191108 $ f_query_main . $ f_query_from . $ f_query_filter
11201109 . $ f_query_order . $ f_query_limit
11211110 );
1122- if ($ disp && $ this -> dbi -> numRows ($ disp ) > 0 ) {
1111+ if ($ disp && $ disp -> numRows () > 0 ) {
11231112 // If a resultset has been created, pre-cache it in the $disp_row
11241113 // array. This helps us from not needing to use mysql_data_seek by
11251114 // accessing a pre-cached PHP array. Usually those resultsets are
11261115 // not that big, so a performance hit should not be expected.
1127- $ disp_row = [];
1128- while ($ single_disp_row = @$ this ->dbi ->fetchAssoc ($ disp )) {
1129- $ disp_row [] = $ single_disp_row ;
1130- }
1131-
1132- @$ this ->dbi ->freeResult ($ disp );
1116+ $ disp_row = $ disp ->fetchAllAssoc ();
11331117 } else {
11341118 // Either no data in the foreign table or
11351119 // user does not have select permission to foreign table/field
@@ -1388,10 +1372,8 @@ public function renameTable($source_db, $target_db, $source_table, $target_table
13881372 *
13891373 * @param string|null $newpage name of the new PDF page
13901374 * @param string $db database name
1391- *
1392- * @return int|false
13931375 */
1394- public function createPage (?string $ newpage , PdfFeature $ pdfFeature , $ db )
1376+ public function createPage (?string $ newpage , PdfFeature $ pdfFeature , $ db ): int
13951377 {
13961378 $ ins_query = 'INSERT INTO '
13971379 . Util::backquote ($ pdfFeature ->database ) . '. '
0 commit comments