Skip to content

Parameter in SELECT or JOIN  #25

@andrewteg

Description

@andrewteg

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions