I am attempting to select column names from a SQL Server database with the following code:
public function getColumns($table){
$columns = array();
$sql = "select column_name from information_schema.columns where table_name = 'dbo.myTable'";
$stmt = $this->conn()->prepare($sql);
try {
if($stmt->execute()){
$raw_column_data = $stmt->fetchAll(PDO::FETCH_ASSOC);
//
//this is empty so we can stop right there
//
echo "<pre>";
print_r($raw_column_data);
echo "</pre>";
}else{
echo "<pre>";
print_r($stmt->errorInfo());
echo "</pre>";
}
return $columns;
} catch (Exception $e){
return $e->getMessage(); //return exception
}
}
Any ideas why the '$raw_column_data` array might be null? I have searched google high and low with no luck. I am almost positive that this is the correct syntax, and I am sure it is querying the database correctly.