gpt4 book ai didi

php - 无法将 1 增量添加到 SQL 中的用户变量

转载 作者:行者123 更新时间:2023-11-29 09:05:48 26 4
gpt4 key购买 nike

这可能是由于变量@count未被识别为整数,但在我的研究中,我遇到了许多类似于@count = @count + 1的示例>;这就是为什么我很困惑为什么这会在引入时破坏我的代码:

$setCount = "SELECT @count:=5";
$uncategorise = "UPDATE pictures
SET category = '0',
pictureorder = @count,
@count:=@count+1
WHERE category = '$categoryID'
AND username = '$username';
$queryCount = mysql_query($setCount) or die(mysql_error());
$queryUncat = mysql_query($uncategorise) or die(mysql_error());

最佳答案

因为这是一个 user defined variable ,
仅适用于相同的 session /连接

You can store a value in a user-defined variable in one statement and then refer to it later in another statement. This enables you to pass values from one statement to another. User-defined variables are connection-specific. That is, a user variable defined by one client cannot be seen or used by other clients. All variables for a given client connection are automatically freed when that client exits.

有一个简单的解决方案 - php mysqli_multi_query

关于php - 无法将 1 增量添加到 SQL 中的用户变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7065244/

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