Search code examples
phpsql-server-2000sqlsrv

What do these NULLS mean?


From this page over at Microsoft; http://msdn.microsoft.com/en-us/library/cc626305.aspx, they give examples on how to use paramaterized queries by showing how to properly build an array. Here is a snippet of sample code:

$params1 = array(
               array($employeeId, null),
               array($changeDate, null, null, SQLSRV_SQLTYPE_DATETIME),
               array($rate, null, null, SQLSRV_SQLTYPE_MONEY),
               array($payFrequency, null, null, SQLSRV_SQLTYPE_TINYINT)
           );

I understand the variables and the constants, but they fail to explain what the nulls are for. Sometimes they are used, sometimes they aren't and sometimes there are two;

variable, null, null, constant

Can someone explain this to me, or point me to the right place? I can't find any reading material about this.

Thank you.


Solution

  • This is akin to invoking an overloaded function. Sometimes the function takes 2 parameters:

           array($employeeId, null)  
    

    sometimes it is 4:

               array($rate, null, null, SQLSRV_SQLTYPE_MONEY)
    

    Placing null in these function calls generally means no value. If you look at the different queries/functions that get invoked from these you will most likely see that the parameters are used in different ways. Further a null passed into the function implies that it would be an optional parameter, which is why it comes in as no value or null.