I am having a syntax issue with MDB2. Our framework uses this frequently so its kinda necessary that I use MDB2. I am trying to build a query with the LIKE mysql function and also trying to use %% to find any results close to the search but I keep getting PEAR errors. Here is the code I'm using.

	public function searchThisUserField($field, $search) {
		$statement = $this->readconnection->prepare("SELECT * FROM user          WHERE " . $field . " LIKE %?% ORDER BY user_id ASC");
$data = array($search); 
$result = $statement->execute($data);
if (PEAR::isError($result)){
			dbg('problems finding with this search');
			exit('problems finding results with this search');
		} else {
			return $result->fetchAll();
		}		
	}

the problem lies with using modulus in the associative array $data. Can someone give me a solution? Would be greatly appreciated

    Can you post your solution to assist others that may run into the same issue in the future?

      solution follows:

      	public function searchThisUserField($field, $search) {
      		$statement = $this->readconnection->prepare("SELECT * FROM user              WHERE " . $field . " LIKE '%$search%' ORDER BY user_id ASC");
      		//$data = array($search);
      		$result = $statement->execute();
      		if (PEAR::isError($result)){
      			dbg('problems finding with this search');
      			exit('problems finding results with this search');
      		} else {
      			return $result->fetchAll();
      		}		
      	}
      

      probably not the best solution to this as not using a prepared statement but i works for now

        Write a Reply...