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

Placeholder triples for where() and having() clauses #164

Open
dc2xl opened this issue Apr 24, 2018 · 0 comments
Open

Placeholder triples for where() and having() clauses #164

dc2xl opened this issue Apr 24, 2018 · 0 comments

Comments

@dc2xl
Copy link

dc2xl commented Apr 24, 2018

Hi all,

In PR #142 @pmjones suggests a more concise way to handle prepared statement placeholders because the 3.x version feels clunky and verbose. His suggestion uses sequential placeholders and we prefer to use named placeholders for documentation and easier debugging.

So here is a suggestion, which supports a single named placeholder only, but works very well for us because of its conciseness. Usage is like this

$select->where("foo = ", ":FOO", "value")->where("bar IN ", "(:BARS)", [1, 2, 3]);
// AND WHERE foo = :FOO AND WHERE bar IN (:BARS)

Interface looks like this:

/**
 *
 * ADD a WHERE condition with a prepared statement placeholder and value to the query.
 *
 * @param string $cond the first part of the where condition without the placeholder. e.g. "foo = " or "bar IN"
 * @param string $placeholder the placeholder as a string. e.g. ":FOO" or "(:BARS)"
 * @param (string|int|float|array) $value the value to bind to the placeholder. e.g. "abc" or [1, 2, 3]
 * @return $this
 */
public function where(string $statement, string $placeholder, $bindValue);

Of course there should corresponding versions for orWhere, having .

This is a feature/discussion request. We have extended the ExtendedPDO inhouse to provide the request functionality. I could polish it up, add missing parts and contribute a PR if the project is interested.

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

1 participant