我正在創建一個數據庫到CSV導出功能。 我正在使用MySQL轉換函數來轉換日期,但它似乎並沒有工作。MySQL「轉換」似乎沒有工作
,我得到的錯誤是: -
string(140) "SELECT userid,firstname,lastname,email,CONVERT(VARCHAR(10),registrationdate, 101) as registrationdate from users order by userid LIMIT 0,30" You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'VARCHAR(10),registrationdate, 101) as registrationdate from users order by user' at line 1
代碼
<?php
include '../inc/inc.functions.php';
include '../dbconnector.php';
include '../dbpdo.php';
$query = "SELECT userid,firstname,lastname,email,CONVERT(VARCHAR(10),registrationdate, 101) as registrationdate from users order by userid LIMIT 0,30";
var_dump($query);
$result = mysql_query($query,$db) or die(mysql_error($db));
$array = array();
# Headers
$array[] = array("Serial Number","First Name","Last Name","Email","Registraion Date");
while($row = mysql_fetch_array($result)) {
// $array[] = $row;
$array[] = array($row['userid'],$row['firstname'],$row['lastname'],$row['email'],$row['registrationdate']);
}
array_to_csv_download($array,"records.csv",",");
?>
可能是什麼問題?任何的意見都將會有幫助。
爲什麼你不使用DATE_FORMAT? –