Skip to content

Commit 727754c

Browse files
Merge pull request #1021 from CassianoRafael/master
Title: Prevent Potential Null Issue and Warnings in rawAddPrefix (#1021) Description: This pull request addresses a potential issue in the rawAddPrefix method of the PHP-MySQLi-Database-Class. In newer PHP versions, accessing properties of potentially null variables can trigger warnings. Issue: If the provided SQL query doesn't contain keywords like "FROM," "INTO," "UPDATE," "JOIN," or "DESCRIBE" (e.g., functions and procedures), the $table array used for prefixing might be empty. This could lead to: PHP Deprecated Warnings: Accessing properties of a potentially null $table array can cause warnings in newer PHP versions. Unexpected Behavior: An empty $table array could result in unexpected behavior when adding prefixes. Fix: This pull request introduces a conditional check to ensure there are table name matches before proceeding with prefix replacement. This prevents the $table array from being null and avoids potential warnings and unexpected behavior. Benefits: Improves code robustness and prevents warnings in newer PHP environments. Enhances code clarity and maintainability. Additional Notes: This is a valuable contribution by first-time contributor @CassianoRafael (thanks!).
2 parents 07fec42 + 2f5d7f2 commit 727754c

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

MysqliDb.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,10 @@ public function rawAddPrefix($query){
556556
preg_match_all("/(from|into|update|join|describe) [\\'\\´]?([a-zA-Z0-9_-]+)[\\'\\´]?/i", $query, $matches);
557557
list($from_table, $from, $table) = $matches;
558558

559+
// Check if there are matches
560+
if (empty($table[0]))
561+
return $query;
562+
559563
return str_replace($table[0], self::$prefix.$table[0], $query);
560564
}
561565

0 commit comments

Comments
 (0)