2012-09-04 4 views
0

나는 PHP/mysqli 간단한 검색을 실행하려고 노력했지만, 제대로 작동하지 않는 것 같습니다. 이전 질문 (Link)에서 찾은 몇 가지 지침을 따르고 있지만 여전히 작동하지 않습니다. 이 오류 메시지가 발생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()에 대한 잘못된 매개 변수 수는"감사하겠습니다.

+0

또한 확인해야합니다 귀하의'$ 변수 where' - 당신이 포함하고'WHERE' 그들 각각; 둘 다 설정되면 SQL 문은 두 개의'WHERE'으로 끝나게됩니다. – andrewsi

+0

말해 주셔서 감사합니다. 지금 바뀌 었습니다. – Markus

답변

2

mysqli_stmt :: bind_param 2 개 매개 변수의 최소 예상,하지만 당신은 하나의

구문을 전달하는 :

bool PDOStatement::bindParam (mixed $parameter , mixed &$variable [, int $data_type = PDO::PARAM_STR [, int $length [, mixed $driver_options ]]]) 

경우

매개 변수 : 매개 변수의 식별자입니다. 자리 표시자를 사용하여 준비된 명령문의 경우 name : name 형식의 매개 변수 이름이됩니다. 물음표 자리 표시자를 사용하여 prepared statement를 사용할 경우 1-indexed parameter의 위치가됩니다.

변수 : SQL 문 에 바인드 할 PHP 변수의 이름입니다.

data_type : PDO :: PARAM_ * 상수를 사용하는 매개 변수의 명시 적 데이터 유형. 저장 프로 시저에서 INOUT 매개 변수를 반환하려면 비트 단위 OR 연산자 을 사용하여 data_type 매개 변수의 PDO :: PARAM_INPUT_OUTPUT 비트를 설정하십시오.

길이 : 데이터 형식의 길이. 매개 변수가 저장 프로 시저의 OUT 매개 변수임을 나타내려면 길이를 명시 적으로 설정해야합니다.

당신은이처럼 할 수있는 : 당신이 설정하는 경우

$values = array_unshift($values, $types); 
call_user_func_array (array ($search_stmt, 'bind_param'), $values);   
$search_stmte->execute();