Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP mysqli prepare statement not working
    primarykey
    data
    text
    <p>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:</p> <blockquote> <p>PHP Warning: mysqli_stmt::bind_result(): Number of bind variables doesn't match number of fields in prepared statement in C:\wamp\www\firecom\firecom.php on line 80</p> <p>PHP Notice: Undefined variable: results in C:\wamp\www\firecom\firecom.php on line 89</p> </blockquote> <p>Both parameters are being set correctly but something is throwing it off.</p> <p>Code: </p> <pre><code>$query = $mysqli-&gt;prepare("SELECT * FROM calls WHERE wcccanumber = ? &amp;&amp; county = ?"); $query-&gt;bind_param("ss", $wcccanumber, $county); $query-&gt;execute(); $meta = $query-&gt;result_metadata(); while ($field = $meta-&gt;fetch_field()) { $parameters[] = &amp;$row[$field-&gt;name]; } call_user_func_array(array($query, 'bind_result'), $parameters); while ($query-&gt;fetch()) { foreach($row as $key =&gt; $val) { $x[$key] = $val; } $results[] = $x; } print_r($results['0']); </code></pre> <p>$query var_dump:</p> <pre><code>object(mysqli_stmt)#27 (10) { ["affected_rows"]=&gt; int(-1) ["insert_id"]=&gt; int(0) ["num_rows"]=&gt; int(0) ["param_count"]=&gt; int(2) ["field_count"]=&gt; int(13) ["errno"]=&gt; int(0) ["error"]=&gt; string(0) "" ["error_list"]=&gt; array(0) { } ["sqlstate"]=&gt; string(5) "00000" ["id"]=&gt; int(1) } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload