Yii2 数据库操作求解

Xiaopeng 发布于 2016/09/06 18:32
阅读 464
收藏 0
Yii

现在有这样的一个数据库查询语句,我在Navicat里可以查询,但放到Yii2的框架已就报错,求高手指点,谢谢~

SET @ranking = 0;
SELECT
	*
FROM
	(
		SELECT
			*, @ranking :=@ranking + 1 AS ranking
		FROM
			user_match
		WHERE
			user_id != ''
		ORDER BY
			CONVERT (
				user_match.player_score,
				SIGNED
			) DESC
	) AS result
WHERE
	result.player_score = 365
LIMIT 1


报错信息:
Database Exception – yii\db\Exception

SQLSTATE[HY000]: General error
The SQL being executed was: SET @ranking = 0;SELECT * FROM (SELECT *, @ranking :=@ranking + 1 AS ranking FROM user_match WHERE user_id != '' ORDER BY CONVERT(user_match.player_score, SIGNED) DESC) AS result WHERE result.player_score=365 LIMIT 1;
Error Info: Array
(
    [0] => HY000
)
↵
Caused by: PDOException

SQLSTATE[HY000]: General error



加载中
0
小紫羽
小紫羽

PDO因为安全的原因,不支持一次发送执行两句sql,

你的 SET@ranking = 0;已经有个分号了

返回顶部
顶部