mysql - Is there a way to make a param optional in PHP PDO? -
say have query:
$qry = 'select p.id products p p.type = :type , p.parent = :parent';
if wanted make "type" optional way know how this:
$qry = 'select p.id products p p.parent = :parent'; if(isset($type)) { $qry .= 'and p.type = :type'; }
is best way? wondering if there way can keep original, , use sort of parameter indicate optional... example if $type = "*" pull types.
whats best way this?
you might want check blank values well
if(isset($type) && $type != '') { $qry .= 'and p.type = :type'; }
Comments
Post a Comment