1

用于 SQL 查询。

是否可以通过 GET 传递 OR?

variable=value OR othervalue

或者更容易定义多个变量,然后从多个变量中进行 SQL 过滤器。

4

1 回答 1

1

你应该GET像这样传递你的参数:

script.php?variable[]=happy&variable[]=sad

在您的脚本中,这些将$_GET[variable]作为数组存储:

大批
(
    [0] => 快乐
    [1] => 伤心
)

然后您可以绑定参数并发送您的语句(尚未测试):

<?php
$link = mysqli_connect('localhost', 'my_user', 'my_password', 'world');

/* check connection */
if (!$link) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

$type = '';

$query = 'SELECT column FROM bubbles WHERE variable IN (';

for($i = 0; $i < count($_GET[variable]); $i++) {
   $query .= '?';
   $type .= 's';
   if($i+1 < count($_GET[variable])) $query .= ', ';
}

$query .= ')';

$stmt = mysqli_prepare($link, $query);

call_user_func_array('mysqli_stmt_bind_param', array_merge(array($stmt, $type), $_GET[variable])); 

/* execute prepared statement */
mysqli_stmt_execute($stmt);

/* close connection */
mysqli_close($link);
?>
于 2013-02-09T15:20:04.950 回答