Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/269.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 Sql请求错误语法_Php_Mysql_Sql_Mysql 8.0 - Fatal编程技术网

Php Sql请求错误语法

Php Sql请求错误语法,php,mysql,sql,mysql-8.0,Php,Mysql,Sql,Mysql 8.0,嘿,伙计们,我的问题很简单:我有一个要求: ->prepare("SELECT CONCAT(YEAR(`p`.`created_account`), '-', MONTH(`p`.`created_account`)) AS `month` FROM `profile` AS `p` GROUP BY YEAR(`p`.`created_account`), MONTH(`p`.`created_account`)"); 我在mysql 5中工

嘿,伙计们,我的问题很简单:我有一个要求:

->prepare("SELECT
    CONCAT(YEAR(`p`.`created_account`), '-', MONTH(`p`.`created_account`)) AS `month` 
    FROM
   `profile` AS `p` 
    GROUP BY
    YEAR(`p`.`created_account`), MONTH(`p`.`created_account`)");
我在mysql 5中工作,但我升级到mysql 8,知道我有以下错误:

objectDoctrine\DBAL\Exception\SyntaxErrorException 707 8{[driverException:Doctrine\DBAL\Exception\driverException:private]=>objectDoctrine\DBAL\Driver\PDOException:766 10{[errorCode:Doctrine\DBAL\Driver\PDOException:private]=>int1064[sqlState:Doctrine\DBAL\Driver\PDOException:private]=>string5 42000[消息:受保护]=>string282 SQLSTATE[42000]:语法错误或访问冲突:1064您的SQL语法有错误;请查看与您的MySQL服务器版本对应的手册,以获取正确的语法,以便在“按年份从配置文件中按p组创建”附近使用。创建的帐户,MONTHp。第1行的“创建的a”[字符串:异常:私有]=>string0[代码:受保护]=>string5 42000[文件:受保护]=>string92

如果这有帮助的话,我有一个可以在两个版本中使用的:

->prepare("SELECT COUNT(`p`.`id`) AS `total` FROM `profile` AS `p` GROUP BY YEAR(`p`.`created_account`), MONTH(`p`.`created_account`)");

当我删除有效但未分组的分组依据时:,我有:

array9{[0]=>array1{[month]=>string6 2018-6}[1]=>array1{[month]=>string6 2018-6}[2]=>array1{[month]=>string6 2018-7}[3]=>array1{[month]=>string6 2018-8}[4]=>array1{[month]=>string6 2018-8}[5]=>array1{[month]=>string6 2018-8}[6]=>[8] =>array1{[月]=>string6 2018-8}


那个么我该怎么做才能不在同一个月重复呢?thx对于所有试图回答的问题:p

似乎你们错过了一个与CONCAT密切相关的大括号 你能试试吗

SELECT CONCAT(YEAR(`p`.`created_account`), '-', MONTH(`p`.`created_account`)) AS `month` FROM `profile` AS `p` GROUP BY YEAR(`p`.`created_account`), MONTH(`p`.`created_account`)

好的,我发现对于有同样问题的人,可以这样做:似乎mysql的v8不允许按年份或月份分组,所以只需这样做:

->prepare("SELECT DISTINCT CONCAT(YEAR(`p`.`created_account`), '-', MONTH(`p`.`created_account`)) AS `month` FROM `profile` AS `p` GROUP BY (`created_account`)");

计算你的错误。当我计算时,同样的错误这不是语法的问题-至少不是根据:这是在MySQLi vardump中设置的唯一完整组的结果吗?dump it结果我忘了把它放在帖子里抱歉,但那不起作用…同样的错误,比如如果我更改了在mysql上工作但在mysql上不工作的版本。奇怪。我使用v8和on我必须做的唯一改变是更改GROUP BY子句。`SELECT concatyerp.date_joined',-',MONTHp.date_joined AS month,从用户按日期p GROUP BY date_joined;`非常奇怪,因为我更改了版本,并且在8.0版本中再次更改了版本,但在我按该版本删除组时不起作用,但不起作用:`就像2018-08年一样-08 2018-09 2018-10 2018-10