PDO bindValue parameter passing

1

I have the following parameter in my UPDATE query.

$consulta->bindValue(':foto', $foto, PDO::PARAM_STR);

What I would like to do is this: If the variable $foto is blank, how could I pass the same value I have in the database?

I ask this because as the variable is coming in white it is doing the update in the field with no value.

    
asked by anonymous 16.09.2016 / 00:39

1 answer

1

I ended up using the mysql function our friend @stderr posted in the comments.

foto=COALESCE(:foto, foto) 

If the parameter is blank, COALESCE assigns a default value to the field, which in my case is the same value as already recorded.

    
20.09.2016 / 00:57