title: MYSQL: Insert column if not exists
body: <p>I am trying to add a column by checking if it exists. If not it should give message that it already exists with the code below.</p>
  
  <pre><code>$prefix = 'vm_';
  $col_name = 'checking';
  
  $col = "SELECT ".$col_name." FROM ".$prefix."users";
  
  if (!$col){
      $insert_col = "ALTER TABLE ".$table." ADD ".$col_name." DATETIME NOT NULL";
  
      mysql_query($insert_col);
  
      echo $col_name.' has been added to the database';
  } else {
      echo $col_name.' is already exists';
  }
  </code></pre>
  
  <p>But it doesn't add any column and directly displays message that the column already exists.</p>