Using wildcards in prepared statement - MySQLi

Posted by Michael Irwin on Stack Overflow See other posts from Stack Overflow or by Michael Irwin
Published on 2009-08-29T18:03:04Z Indexed on 2010/06/06 17:02 UTC
Read the original article Hit count: 368

Hi! I'm trying to run the following query, and I'm having trouble with the wildcard.

   function getStudents() {
    	global $db;
    	$users = array();
    	$query = $db->prepare("SELECT id, adminRights FROM users WHERE classes LIKE ? && adminRights='student'");
    	$query->bind_param('s', '%' . $this->className . '%');
    	$query->execute();
    	$query->bind_result($uid, $adminRights);
    	while ($query->fetch()) {
    		if (isset($adminRights[$this->className]) && $adminRights[$this->className] == 'student')
    			$users[] = $uid;
    	}
    	$query->close();
    	return $users;
    }

I'm getting an error that states: Cannot pass parameter 2 by reference. The reason I need to use the wildcard is because the column's data contains serialized arrays. I guess, if there's an easier way to handle this, what could I do?

Thanks in advance!

© Stack Overflow or respective owner

Related posts about php

Related posts about mysqli