Skip to content

Query binding stopped working #781

Closed
@nowackipawel

Description

@nowackipawel

TL;DR;
https://bcit-ci.github.io/CodeIgniter4/database/queries.html#query-bindings should be updated.


Simple query like this: $tmp = $this->query("SELECT :sth", [':sth' => 'abc']); is causing an exception now.

system/Database/Query.php->matchNamedBinds L: 421
Looks like query binding stopped working because of someone commented that line:
// $sql = preg_replace('|:' . $placeholder . '(?!\w)|', $escapedValue, $sql);
and there is also one missing char:

$sql = preg_replace('|:' . $placeholder . '(?!\w):|', $escapedValue, $sql);

UPDATE

Ok it works if we are binding like this:
SELECT :sth: instead of SELECT :sth .
So I think documentation should be updated (https://bcit-ci.github.io/CodeIgniter4/database/queries.html#query-bindings) or someone add one unnecessary ":" at the end:
$replacers[":{$placeholder}:"] = $escapedValue;
after placeholder.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions