title: Checking MySQL NULL values with PHP
body: <p>This is how my table looks like..</p>
  
  <pre><code>id col1 col2  
  ---------------
  1  a     x
  2  NULL  y
  3  NULL  z
  4  NULL  t
  </code></pre>
  
  <p>col1 has a default value of <code>NULL</code>.</p>
  
  <p>I want to use col1 data If col1 is not null, otherwise use col2 data. </p>
  
  <pre><code>function something($col1,$col2)
  {
     if(is_null($col1) == true)
        $var = $col2
     else
        $var = $col1
  
     return $var;
  }
  
  function something2($col1,$col2)
  {
     if($col1 === NULL)
        $var = $col2
     else
        $var = $col1
  
     return $var;
  }
  </code></pre>
  
  <p>Here is my problem. Both of these functions returns $col2 values. But as you can see in first row, col2 column is not null. What am I doing wrong? <strong>UPDATE: Looking for a solution with PHP and I need both col1 and col2 values.</strong></p>
  
  <p>Also I want to learn, Does using NULL values is the best practice for this example?</p>