Topic: db connection scripts fixes

The db connection scripts reside in the includes/db/ folder.

The currently acceptable db drivers there are:

connect_db_mysqli.inc
connect_db_mysql.inc

Line 15 in the MySQLi driver file above is:

$db_last_inserted_id = 0;

This needs to be ported to the MySQL driver too.

The function db_query() in both driver files have a line (78/79):

        if ($SysPrefs->select_trail || (strstr($sql, 'SELECT') === false)) {

It is better coded to make the SELECT be the beginning part of the search string and case insensitive as well (stristr ?) like:

        $sql = trim($sql);
        if ($SysPrefs->select_trail || (preg_match('/^SELECT/i', $sql) === 0)) {

According to the PHP Manual:

preg_match() returns the number of times pattern matches. That will be either 0 times (no match) or 1 time because preg_match() will stop searching after the first match.

Re: db connection scripts fixes

@joe: any thoughts?

Re: db connection scripts fixes

Not really, maybe a change to stristr instead of strstr.

/Joe

Re: db connection scripts fixes

The stristr is okay to fix instead of the regex except that it will not address checking if it is the first word in the sql.
The idea is that it should be the beginning of the string and not inbetween like CREATE TABLE xxx SELECT * from ....

Re: db connection scripts fixes

Following our non-written coding policy regarding sql statements (like using capital letters for sql keywords) there is no need for additional cleanups here :-).
Janusz

Re: db connection scripts fixes

Isn't it better to be a little permissive when a change from strstr to stristr isn't any great penalty?
And also a check to see if it is the first word in the sql?

Also if it is not going to be fixed in the core it will reside in my FA24Mods.
Thanks for the policy info.