它适用于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