PHP-DB icon indicating copy to clipboard operation
PHP-DB copied to clipboard

Parameter in SELECT or JOIN

Open andrewteg opened this issue 1 year ago • 1 comments

I know this isn't ideal, but I have a query where it basically is joining up a lookup table and the $child_pk var could be any number of a few strings like email, url, etc. I'd like to join on that field and have it be a variable so I'm not rewriting the same query so I have it as: LEFT JOIN $child_mod ON child_id = $child_pk

If I change it to LEFT JOIN $child_mod ON child_id = ? and add a parameter to the query $db->select($strSQL, [$child_pk]) style then I get an error of "ERROR: invalid input syntax for type integer" as I suspect it is doing ON child_id = 'email' instead of ON child_id = email as it parses out that $child_pk is a string.

Is there any way around this, or is it best to leave LEFT JOIN $child_mod ON child_id = $child_pk and run it through a custom function for security's sake before I call the select? I figure I probably should run it through a check of some sort anyways as it's likely to show up in an AJAX call, but wasn't sure if there was a better way to handle this in PHP-DB.

Thanks.

andrewteg avatar Dec 28 '22 00:12 andrewteg