I use this script to backup the mysql database.

I have the problem that the null values return as "" but some queries depends on null values.
How can I fix this (to return null as null)?
Code:
for ($i = 0; $i < $num_fields; $i++)
        {
 while($row = mysql_fetch_row($result))
            {
 $return.= 'INSERT INTO '.$table.' VALUES(';
 for($j=0; $j<$num_fields; $j++)
   {
  $row[$j] = addslashes($row[$j]);
  $row[$j] = ereg_replace("\n","\\n",$row[$j]);
   if (isset($row[$j])) { //if (empty($row[$j]))
  //  $a='null';else
   // $a='"'.$row[$j].'"';
    $return.= '"'.$row[$j].'""' ; } else { $return.= '""'; }
   if ($j<($num_fields-1)) { $return.= ','; }
     }
   $return.= ");\n";
   }
        }