mysql变量 PHP变量,用MySQLi设置MySQL变量(不是PHP变量)

它适用于PHP变量:

从查询功能中预先设置一个结果

extract($GLOBALS);

$GLOBALS['mysqli'] = $mysqli;

function select($a,$b){

$mysqli = $GLOBALS['mysqli'];

$query = $mysqli -> query($b);

while($row = ($query -> fetch_assoc())){

return $row[$a]."
";

}// while

$query -> free();

}

点击的顺序

$self = "SELECT order FROM channels WHERE id='$id'";

$self = "(SELECT order FROM (($self)AS x))";

if($btn == "Up"){

// Order previows

$other = "SELECT MAX(order) FROM channels WHERE order < $self";

}

if($btn == "Down"){

// Order next

$other = "SELECT MIN(order) FROM channels WHERE order > $self";

}

$other = "SELECT order FROM channels WHERE order=($other)";

设置MYSQL VARIABLE的PHP变量INSTEAD

$other = select(‘order’,$other);

$query = "UPDATE channels SET order=$self WHERE order='$other';";

$query .= "UPDATE channels SET order='$other' WHERE id='$id'";

$mysqli->multi_query($query);

问题?我需要使用一个MySQL查询更快的查询

这不起作用:

设置MYSQL VARIABLE INSTEAD O PHP VARIABLE

$query = "DEFINE other INT;"; // return: 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 'DEFINE other INT(...);

$query .= "DECLARE other INT;"; // return: 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 'DECLARE other INT(...);

$query .= "SET other = $other;"; // return: Unknown system variable 'other'

$query .= "UPDATE channels SET order=$self WHERE order=other;";

$query .= "UPDATE channels SET order=other WHERE id='$id'";

$mysqli->multi_query($query);

解决方法:

User-Defined Variables

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

session-specific. That is, a user variable defined by one client

cannot be seen or used by other clients. All variables for a given

client session are automatically freed when that client exits.

User variables are written as @var_name, where the variable name

var_name consists of alphanumeric characters, “.”, “_”, and “$”. A

user variable name can contain other characters if you quote it as a

string or identifier (for example, @’my-var’, @”my-var”, or

@my-var).

$query .= "SET @other = $other;"; // return: Unknown system variable 'other'

标签:php,variables,mysql,mysqli,set

来源: https://codeday.me/bug/20191003/1848321.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值