简体   繁体   中英

mysqli_stmt::bind_result(): Number of bind variables doesn't match number of fields in prepared statement in

I am using a prepared statement I have passed exactly the same amount of variable in bind_param as I am expecting but still it is giving me an error of variable count doesn't match.

$query = "select `shipping_name`,`shipping_address1`,`shipping_address12`,`shipping_city`,`shipping_state`,`shipping_postalcode`,`billing_name`,`billing_address2`,`billing_address22`,`billing_city`,`billing_state`,`billing_postalcode` from puppy_shipping where unique_id=?";
$stmt = $db->prepare($query);
$bind = 'ssssssssssss';
if ($stmt) {
    $stmt->bind_param('s', $id);
    $stmt->execute();
    $stmt->bind_result($bind, $shipping_name, $shipping_address1, $shipping_address12, $shipping_city, $shipping_state, $shipping_postalcode, $billing_name, $billing_address2, $billing_address22, $billing_city, $billing_state, $billing_postalcode);
    while ($stmt->fetch()) {
    }
    $stmt->close();
}

Your problem is with this line

$stmt->bind_result($bind, $shipping_name,$shipping_address1,$shipping_address12, ....);

You're trying to bind the variable-types, like you do with bind_param() , which is wrong - because this function does not have a parameter like that. bind_result() s only arguments are the values you select from the query, nothing else.

The solution is to simply remove $bind from your bind_result() call, making it

$stmt->bind_result($shipping_name, $shipping_address1, $shipping_address12, ....);

Reference

Object oriented style

$stmt->bind_result($name, $code);

Procedural style

mysqli_stmt_bind_result($stmt, $name, $code);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM