mrcrypster/mysqly

IN-array values error

Closed this issue · 1 comments

In the documentation you say the placeholder in the SELECT-statement and bind-array can be ":ids". But to make the code work, the placeholder-name in de array needs to be without the colon (":").

Issue is in line 93, where you replace the current placeholder with the new generated placeholders. The search parameter looks for ":" + original placeholder-name in the bind-array. When using ":ids" as placeholder-name, the search-string is actually "::ids". This will return an error (Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in mysqly.php:110)

Example:
$rows = mysqly::fetch( 'SELECT id, age FROM users WHERE id IN (:ids)', [':ids' => [6, 7]] );
will not work and returns an error.
When used as:
$rows = mysqly::fetch( 'SELECT id, age FROM users WHERE id IN (:ids)', ['ids' => [6, 7]] );
it works.
Deleting the ":" on line 93 does not work.

Ps. the , is also missing in the example on the documentation after the SELECT-statement.

Fixed both lib & docs. Though it's better to skip ":" in this case, added support for both ids and :ids in parameters. also fixed docs. Sorry for super slow reaction, war in Ukraine affects me directly (I'm Ukrainian).