I'm trying to create columns in my database ,but when I run the code I get
Fatal error: Call to a member function fetchAll() on boolean on line 16
$con = connect(DNS,USERNAME,PASSWORD);
//columns as arrays that i need to create if it doesn't exist
$columnname = array("urine_re","lab_investigation","a_records","crazy_gus");
$table='anc_hsd';
//function to check if column name exist if not create it
function columnExist($item,$table,$column){
  $exists = false;
  $sql = "SHOW COLUMNS FROM  $table";
  $result = $item->query($sql);
  $results=$result->fetchAll(PDO::FETCH_COLUMN);
  if(in_array($column,$results)){
    $exists=true ;
  }
  if(!$exists){
    $sql="ALTER TABLE $table ADD $column  INT(30) NULL";
    $item->exec($sql);
  }
}
//this is where I use the function
foreach($columnname as $key=>$value){
  columnExist($con, $table, $value);
}
 
     
    