Ensured parametrised queries respect data types #39
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
If using
Database::execute()with an array of values of varying types, particularly booleans or ints, they are encased in quotes, causing them to be interpreted as strings.This would result in the following error:
SQL Error: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'BoolVal' at row 1 (0)This was found by attempting to call a stored procedure that took a
bitas a parameter, in which the boolean in PHP was passed as a string, violating the max length of the parameter.Below is some sample code I used to replicate the issue before the fix:
MySQL Stored Procedure:
PHP Code:
Note: I could not test for the same erroneous behaviour using named parameters, as I believe MySQL does not support them in stored procedures. I included the fix in that
foreachloop anyway as it looks like it would encounter the same issue if used.