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

Support prepared statements #19

Closed
mbabker opened this issue Sep 2, 2018 · 1 comment
Closed

Support prepared statements #19

mbabker opened this issue Sep 2, 2018 · 1 comment

Comments

@mbabker
Copy link
Contributor

mbabker commented Sep 2, 2018

Now that the database API consistently uses (and requires) prepared statement support, this package should support that as well. To do a lookup by anything that's not a PK still requires manual quoting of all values.

// Current behavior
$data = (new MyModel)->where('name = ' . $db->quote($name))->get();

// Preferred behavior
$data = (new MyModel)->where('name', '=', $name);

// With this method prototype in the Query class
public function where(string $column, $value, string $operator = '=', string $glue = 'AND')
{
    $paramName = ':' . $column;

    $this->query->where($column . ' ' . $operator . ' ' . $paramName, $glue);

    // TODO - Support defining the parameter type too, or at least detecting based on the $value param type?
    $this->query->bind($paramName, $value);

    return $this;
}
@wilsonge
Copy link
Contributor

Closing for the PR in #20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants