0列MySQL中的值而不是NULL

I have a script that geocodes physical addresses and puts it into a MySQL database with two columns: coord_lat and coord_long. These are float type columns but unfortunately some addresses don't get geocoded correctly and the script tries to push the address as a null value into the database which then breaks the script because the database cannot hold a null value.

I'm trying to find a way I can rewrite my script to determine if the geocoded address comes out to a null value to automatically rewrite that value to 0 so that the database and script don't break.

Can anyone give me some advice on switching/replacing a null values to 0?

If the value is NULL, then assign 0

if(is_null($value)){
  $value = 0;
}

try this:

if PHP (shorthand if)

(is_null($value) ? 0:$value)

else if MySQL (coalesce function)

SELECT COALESCE(@your_value_here,0) FROM dual

for reference of coalesce: http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html

for shorthand if statement (ternary):http://davidwalsh.name/php-ternary-examples