Closed
Description
Information
- Version of Medoo: 2.1.11
- Version of PHP: 8.2.9
- Type of Database: Mysql 8
- System: Linux
Describe the Problem
The like operator [~] does not work as expected.
Code Snippet
The detail code you are using that causes the problem:
##skipped medoo init code
$this->database->select("test_table", "*", [
'field[~]' => 'abc%'
]);
Expected Behavior
the above code should generate and execute the sql "select * from test_table where field like 'abc%'"
Actual Behavior
An sql error "SQLSTATE[HY093]: Invalid parameter number: parameter was not defined" occurred
The issue should be related to the fix 1a892c7 of #1109. It seems that the sql statement is not correctly parse by PDO when the parameter placeholder contains a "$".
The issue could be resolved by changing the ending "$" in the placeholder to a "L".
From
$likeClauses[] = $column . ($operator === '!~' ? ' NOT' : '') . " LIKE {$mapKey}L{$index}$";
$map["{$mapKey}L{$index}$"] = [$item, PDO::PARAM_STR];
to
$likeClauses[] = $column . ($operator === '!~' ? ' NOT' : '') . " LIKE {$mapKey}L{$index}L";
$map["{$mapKey}L{$index}L"] = [$item, PDO::PARAM_STR];