giandonatoinverso / PHP-Dynamic-Qr-code

PHP Dynamic Qr code is a script that allows the generation and saving of dynamic and static QR codes
MIT License
243 stars 73 forks source link

Inconsistency of using DATABASE_PREFIX with getOne() #92

Closed tranmh closed 4 months ago

tranmh commented 4 months ago

Obviously you are using DATABASE_PREFIX for 3 of the getOne() queries, but not for all:

$ grep -nr getOne * authenticate.php:17: $row = $db->getOne('users'); bulk_action.php:32: $row = $db->getOne("{$type}_qrcodes"); index.php:29:$numScan = $db->getOne(DATABASE_PREFIX."dynamic_qrcodes", "sum(scan) as numScan"); lib/Qrcode/Qrcode.php:35: $result = $db->getOne($this->table); lib/Users/Users.php:43: $result = $db->getOne(DATABASE_PREFIX.'users'); lib/Users/Users.php:82: $row = $db->getOne('users'); login.php:21: $row = $db->getOne('users'); read.php:10:$qrcode = $db->getOne(DATABASE_PREFIX."dynamic_qrcodes");

Using the non-Docker setting in config/environment.php and set: define('DATABASEPREFIX', "qr"); // This must have a trailing underscore. Example: qr_ I see errors throwing with duplicating prefix. Fatal error: Uncaught mysqli_sql_exception: Table 'c4C0310.qr_qr_dynamic_qrcodes' doesn't exist in /var/www/clients/client4/web64/web/PHP-Dynamic-Qr-code/src/lib/MysqliDb/MysqliDb.php:1988 Stack trace: #0 /var/www/clients/client4/web64/web/PHP-Dynamic-Qr-code/src/lib/MysqliDb/MysqliDb.php(1988): mysqli->prepare() #1 /var/www/clients/client4/web64/web/PHP-Dynamic-Qr-code/src/lib/MysqliDb/MysqliDb.php(1594): MysqliDb->_prepareQuery() #2 /var/www/clients/client4/web64/web/PHP-Dynamic-Qr-code/src/lib/MysqliDb/MysqliDb.php(738): MysqliDb->_buildQuery() #3 /var/www/clients/client4/web64/web/PHP-Dynamic-Qr-code/src/lib/MysqliDb/MysqliDb.php(764): MysqliDb->get() #4 /var/www/clients/client4/web64/web/PHP-Dynamic-Qr-code/src/index.php(29): MysqliDb->getOne() #5 {main} thrown in /var/www/clients/client4/web64/web/PHP-Dynamic-Qr-code/src/lib/MysqliDb/MysqliDb.php on line 1988

Pretty unsure, if we need to fix lib/Users/Users.php:36: return $db->get(DATABASE_PREFIX.'users'); as well.

With the fixes in this Pull Request, everything is fine. I have tested it for the 3 modified positions. So I hope you accept the Pull Request.

Thx.

giandonatoinverso commented 4 months ago

well done. Thank you so much

abhilesh commented 3 months ago

I see that this bugfix was added in v2.2.3, does this affect already generated QR codes that were generated using the previous versions?