Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php MySQL“;转换;不';我好像不工作_Php_Mysql - Fatal编程技术网

Php MySQL“;转换;不';我好像不工作

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

我正在创建一个数据库到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 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