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

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -