Currently doing a Moodle upgrade from 1.9.19 => 2.2.17 => 2.7 => 3.2, and I'm in the middle of upgrading & app development.
I get error, when using the following code (table doesn't exist or error in your SQL syntax):
$DB->delete_records($table);It likely happens because I use the www.mymoodle.com as database name, and _mytable as table name.
Using dot in database name is non-conventional, but it is still valid name if it is quoted well using double quotes or backticks.
The problem is, that in /lib/dml/mysqli_native_moodle_database.php the emulate_bound_params() is called, which escapes & adds quote around the the strings:
$param = $this->mysqli->real_escape_string($param);
$return .= "'$param'";
This adds single quotes around the strings, which is not enough for non-conventional names.
Double quotes or backticks would be required in this case.
Current single quote solution results the following SQL code, which doesn't work for non-conventional database & table names (i.e: which has dot in the name):
TRUNCATE TABLE 'www.mymoodle.com'.'_mytable'
Which will point to non-existent database, as the db name is invalid, unless it is not double quoted.
The following SQL code works successfully in MySQL client. This would be the awaited result this for non-conventional database & table naming:
TRUNCATE TABLE `www.mymoodle.com`.`_mytable`
Could be possible to add support for dots in database & table names of MySQL driver?
I checked the Moodle git repo, and seems the code has the same bug in the latest code in master branch (current latest commit is weekly on-sync release 3.4dev).