Php MySQL“;转换;不';我好像不工作
我正在创建一个数据库到CSV导出功能。 我正在使用MySQL convert函数来转换日期,但它似乎不起作用 我得到的错误是:-Php MySQL“;转换;不';我好像不工作,php,mysql,Php,Mysql,我正在创建一个数据库到CSV导出功能。 我正在使用MySQL convert函数来转换日期,但它似乎不起作用 我得到的错误是:- 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 s
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",",");
?>
有什么问题吗?任何建议都会有帮助。MySQL没有,这是SQL Server格式化日期时间的方式
在MySQL中,您可以使用
你为什么不使用日期格式?@user3605847-Hm,我在你的代码中找不到原因。数据库中的
registrationdate
是否为非null,并在中作为查询的一部分正确拼写?是的,它被设置为非null,并且拼写正确。@user3605847在常规SQL提示符下运行查询是否返回正确的结果?
SELECT userid,firstname,lastname,email,
DATE_FORMAT('%m/%d/%Y', registrationdate) as registrationdate
from users
order by userid
LIMIT 0,30