2015-06-15 63 views
1

我正在爲我的團隊構建自定義查詢編寫器,他們只需將查詢放入查詢中,並將其導出到csv文件。它使用ODBC PDO驅動程序。我怎樣才能提取出列名/別名?查詢通常會有這樣的事情:使用ODBC PDO獲取查詢中的列名/別名

$query = "SELECT 
jcst.Loc_No, 
jcst.Emp_No, 
round(Sum(jcst.Amt_1), 2) AS Gross_Wages, 
round(Sum(jcst.Amt_12),2) as Local_Tax, 
round(sum(jcst.Amt_3+jcst.Amt_2),2) As Fica, 
round(sum(jcst.Amt_4),2) as FUTA, 
round(Sum(jcst.Amt_5),2) as SUTA, 
round(sum(jcst.Amt_10),2) as Admin_Fee, 
round(Sum(jcst.Amt_13),2) as Other_Costs 
FROM Master"; 

我需要Loc_No,EMP_NO,Gross_Wages,Local_Tax,FICA,SUTA,Admin_Fee,Other_Costs作爲標題列信息。如何根據查詢獲取列/別名?

感謝

回答

-1

,你可以嘗試,如果你期待的顯示如下

$result = mysqli_fetch_array(....); 
... 
foreach ($result as $res) 
{ 
echo $res['Loc_No']."<br \>"; 
echo $res['Emp_No']."<br \>"; 
echo $res['Gross_Wages']."<br \>"; 
echo $res['Local_Tax']."<br \>"; 
echo $res['FICA']."<br \>"; 
echo $res['SUTA']."<br \>"; 
echo $res['Admin_Fee']."<br \>"; 
echo $res['Other_Costs']."<br \>"; 
} 
.... 
0
$sth->setFetchMode(PDO::FETCH_ASSOC); 

foreach ($sth->fetch() as $key => $value) { 
    $array[] = $key; 
} 

var_dump($array); 

對於那些誰想知道如何做到這一點!