gpt4 book ai didi

php - 无法执行在 phpMyAdmin 中运行的 mysql

转载 作者:行者123 更新时间:2023-12-01 00:01:31 25 4
gpt4 key购买 nike

我有这张 table 用来玩游戏

scores (user,score)

其中有一些条目,我有这个查询:

SET @row_num = 0; 
SELECT @row_num := @row_num + 1 as row_index, user, score FROM scores ORDER BY score DESC

它在 phpmyadmin 中有效,但不适用于 php 代码

$query = "set @row_num = 0; SELECT @row_num := @row_num + 1 as row_index, user, score FROM scores ORDER BY score DESC";
$result = mysql_query($query) or die(mysql_error());

php 已正确连接到 mysql 数据库,在此之前我进行了其他查询并且一切正常

它说:

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 'SELECT @row_num := @row_num + 1 as row_index, user, score FROM scores ORDER BY s' at line 1

你认为它可能是什么?谢谢你,亚历山德罗

最佳答案

这是因为 phpMyAdmin 会根据分号为您拆分查询。 MySQL 服务器不会这样做,PHP mysql 扩展也不会。

您需要将它们分成两个单独的 mysql_query 调用

旁注:PHP mysql 扩展已弃用,建议您对任何新代码使用 PDOmysqli。请在您 future 的开发过程中牢记这一点。

关于php - 无法执行在 phpMyAdmin 中运行的 mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14216880/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com