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

silverlight - Applying a style to ItemContainerStyle in C# -

c# - NullReferenceException in MySqlClient.NativeDriver -

php - Updating recent updates - Problem in procedure - Any other approach? -