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

bindParamsFromArray to also accept associative arguments #41

Open
geertvanbommel opened this issue Apr 20, 2018 · 4 comments
Open

bindParamsFromArray to also accept associative arguments #41

geertvanbommel opened this issue Apr 20, 2018 · 4 comments

Comments

@geertvanbommel
Copy link

In PDO it's common to also provide an associative array of variables in the form of ":name", as well as question mark placeholders. (http://php.net/manual/en/pdostatement.bindparam.php)

So it would be awesome if $query->bindParamsFromArray($args); also supported this.

// Example:
$stmt = 'update table set foo=:bar, foo2=:bar2 where id=:id';

$args = array(':bar'=>'my value',':bar2'=>"my \"second\" value", ':id'=>123);
// or without semicolons:
$args = array('bar'=>'my value',  'bar2'=>"my \"second\" value", 'id'=>123);

// Desired result:
update table set foo='my value', foo2='my "second" value' where id=123

// Potential error in case of mismatching
// SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens
@clue
Copy link
Contributor

clue commented Apr 24, 2018

Yes, please! Would love to see this feature in here. I see there's already some pseudo code in place here: https://github.com/friends-of-reactphp/mysql/blob/master/src/Query.php#L124

Now that the test suite has seen some significant improvements with #39, I suppose this would not be too much work to implement this here. I'm not working on this myself at the moment, but I suppose PRs would be very much appreciated! :shipit:

voku added a commit to voku/mysql that referenced this issue Apr 28, 2018
voku added a commit to voku/mysql that referenced this issue Apr 28, 2018
@clue clue added this to the v0.5.0 milestone Oct 18, 2018
@clue clue removed this from the v0.5.0 milestone Nov 28, 2018
@tonix-tuft
Copy link

Hi, I've created a decorator for the binding of associative parameters, check it out if you are interested:

https://github.com/tonix-tuft/reactphp-mysql-decorator

@WyriHaximus
Copy link
Member

Hi, I've created a decorator for the binding of associative parameters, check it out if you are interested:

tonix-tuft/reactphp-mysql-decorator

Cool, could you add it to: https://github.com/reactphp/react/wiki/Users

@tonix-tuft
Copy link

tonix-tuft commented May 29, 2019

OK! I've added it in the Databases section.

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

No branches or pull requests

4 participants