[英]PHP/MySQLI multiple search
我一直試圖讓php / mysqli簡單的搜索啟動並運行,但我似乎無法讓它工作。 我一直在遵循我在之前的一個問題( 鏈接 )中找到的一些指示,但它仍然無效。
$sql = 'SELECT product_title FROM product ';
$where = array();
$values = array();
$types = '';
if (isset($_GET['searchText']) and $_GET['searchText'] != '') {
$where[] = 'WHERE product_title = ?';
$values['titel'] = $_GET['searchText'];
$types .= 's';
}
if (isset($_GET['searchCategorySelect']) and $_GET['searchCategorySelect'] != '') {
$where[] = 'WHERE product_categoryid = ?';
$values['category'] = $_GET['searchCategorySelect'];
$types .= 's';
}
$sql .= implode(' AND ',$where);
$values = array_unshift($values, $types);
$search_stmt = $mysqli->prepare($sql);
$search_stmt->bind_param($values);
$search_stmt->execute();
這會導致出現此錯誤消息:“mysqli_stmt :: bind_param()中的參數計數錯誤...”
一些建議或幫助將不勝感激。
mysqli_stmt :: bind_param最少需要2個參數,但是你要傳遞一個參數
句法:
bool PDOStatement::bindParam ( mixed $parameter , mixed &$variable [, int $data_type = PDO::PARAM_STR [, int $length [, mixed $driver_options ]]] )
哪里
參數:參數標識符。 對於使用命名占位符的預准備語句,這將是以下形式的參數名稱:name。 對於使用問號占位符的預准備語句,這將是參數的1索引位置。
變量:要綁定到SQL語句參數的PHP變量的名稱。
data_type:使用PDO :: PARAM_ *常量的參數的顯式數據類型。 要從存儲過程返回INOUT參數,請使用按位OR運算符為data_type參數設置PDO :: PARAM_INPUT_OUTPUT位。
length:數據類型的長度。 要指示參數是存儲過程的OUT參數,必須顯式設置長度。
你也可以這樣做:
$values = array_unshift($values, $types);
call_user_func_array (array ($search_stmt, 'bind_param'), $values);
$search_stmte->execute();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.