Passing NULL values into mysql Stored procedure

Posted by McNabbToSkins on Stack Overflow See other posts from Stack Overflow or by McNabbToSkins
Published on 2010-04-28T14:22:07Z Indexed on 2010/04/28 14:33 UTC
Read the original article Hit count: 168

Filed under:

I am trying to pass a few NULL values to a stroed procedure but PHP always retains the varaibles to be empty strings '' and not NULL.

My DB insert function looks like this. (I am using a Framework and ADODB so if it looks weird thats why).

function insert_emp($f_name, $last_name, $dob) {

   if(!isset($dob)){
      $dob = NULL;
   }

   $this->DB->setConnection("CALL insert_emp('$f_name', '$l_name', '$dob')");
}

I have ensured that $dob is being passed an empty string ''. But for some reason when it calls the stored proc it is not changed to NULL. dob is a datetime field and mysql complains that you can not enter an empty string as a DATETIME. If I hard code the insert such as this

 $this->DB->setConnection("CALL insert_emp('Test1', 'Test2', 'NULL')"); 

it will work. Thanks for the help.

© Stack Overflow or respective owner

Related posts about php