PHP SQL GET and OR?


PHP SQL GET and OR?

用于SQL查询。

有可能通过GET传递OR吗?

variable=value OR othervalue

还是更容易定义多个变量,然后从多个变量中进行SQL筛选。

您应该像这样传递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);
?>