Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Like operator does not work #1111

Closed
deadboybun opened this issue Feb 1, 2024 · 1 comment
Closed

Like operator does not work #1111

deadboybun opened this issue Feb 1, 2024 · 1 comment
Labels

Comments

@deadboybun
Copy link

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];
@catfan catfan added the bug label Feb 1, 2024
catfan pushed a commit that referenced this issue Feb 3, 2024
@catfan
Copy link
Owner

catfan commented Feb 5, 2024

Fixed it on 1f035fd.

@catfan catfan closed this as completed Feb 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants