Forum Moderators: coopster

Message Too Old, No Replies

prepared statement variables and parameters

         

bleak26

9:55 am on Jul 6, 2006 (gmt 0)

10+ Year Member



Hi im trying to retrieve all the surnames from a database begining with a particular letter. But ive been recieving the following error:

Warning: mysqli_stmt::bind_param() [function.bind-param]: Number of variables doesn't match number of parameters in prepared statement

The problem is as far as i can see the number of variables im using is equal to the number of parameters.

$stmt = $mysqli->prepare( "SELECT
surname
FROM
customer
WHERE
(surname LIKE '?%')" );

if ( $stmt ) {
$stmt->bind_param("s",$surname);
$stmt->execute();
$stmt->bind_result($surnames);

if ( $stmt->fetch() ) {
print "Get firstname from result $surnames \n";
} else {
print 'Sorry, no records found.';
}

eelixduppy

10:20 am on Jul 7, 2006 (gmt 0)



This is interesting. I don't have much experience with mysqli myself, but here's something you can try:
  • Update your extensions [dev.mysql.com]
  • Or try changing your query to "SELECT surname FROM customer WHERE surname LIKE (?)"

I'm not sure if either of these will work, and I know I changed your query, but if it works then you know it is your query that is the problem. Good luck and I really wish I could have helped you better.