ThingEngineer / PHP-MySQLi-Database-Class

Wrapper for a PHP MySQL class, which utilizes MySQLi and prepared statements.
Other
3.28k stars 1.35k forks source link

Fix rawAddPrefix() to add prefix to all tables in raw query #1034

Open alikm6 opened 1 month ago

alikm6 commented 1 month ago

In the rawAddPrefix function, the prefix is added only to the first table in the query, if we have join and ... in the query, the prefix must be added to the names of all tables.

For example, query

select t1.id as post_id, t2.id as bot_id from posts as t1 inner join bots as t2 on t1.bot_id = t2.id

is converted to

select t1.id as post_id, t2.id as bot_id from tbl_posts as t1 inner join bots as t2 on t1.bot_id = t2.id

when it should be converted to

select t1.id as post_id, t2.id as bot_id from tbl_posts as t1 inner join tbl_bots as t2 on t1.bot_id = t2.id

This issue is resolved in this change.