Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am using a mysqli prepare statement to query my db with multiple constraints. I have ran the code in a test file of mine and it works perfectly fine. However, when I move the code over to my live file it throws the error below:

PHP Warning: mysqli_stmt::bind_result(): Number of bind variables doesn't match number of fields in prepared statement in C:wampwwwfirecomfirecom.php on line 80

PHP Notice: Undefined variable: results in C:wampwwwfirecomfirecom.php on line 89

Both parameters are being set correctly but something is throwing it off.

Code:

$query = $mysqli->prepare("SELECT * FROM calls WHERE wcccanumber = ? && county = ?");
$query->bind_param("ss", $wcccanumber, $county);
$query->execute();

$meta = $query->result_metadata();

while ($field = $meta->fetch_field()) {
    $parameters[] = &$row[$field->name];
}

call_user_func_array(array($query, 'bind_result'), $parameters);

while ($query->fetch()) {
    foreach($row as $key => $val) {
        $x[$key] = $val;
    }
    $results[] = $x;
}

print_r($results['0']);

$query var_dump:

object(mysqli_stmt)#27 (10) { ["affected_rows"]=> int(-1) ["insert_id"]=> int(0) ["num_rows"]=> int(0) ["param_count"]=> int(2) ["field_count"]=> int(13) ["errno"]=> int(0) ["error"]=> string(0) "" ["error_list"]=> array(0) { } ["sqlstate"]=> string(5) "00000" ["id"]=> int(1) }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
986 views
Welcome To Ask or Share your Answers For Others

1 Answer

Why torture yourself with mysqli?
In PDO you will need none of these horrendous codes, but only one line to get the results

$query = $pdo->prepare("SELECT * FROM calls WHERE wcccanumber = ? && county = ?");
$query->execute(array($wcccanumber, $county));
$results = $query->fetchAll();
print_r($results[0]);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...