How to debug SQLSTATE[HY000]: General error: 2031 in prepared statements
<p>I have this prepared statement query </p>

<pre><code>$stmt = $conn-&gt;prepare("
        UPDATE language 
        SET lang_alias=:lang_alias , lang_name=:lang_name  
        WHERE lang_id=:lang_id"
);
</code></pre>

<p>If I set an <strong>array to bind the values</strong> </p>

<pre><code>$query_array = array ( ":lang_alias" =&gt; "en", ":lang_name" =&gt; "English (UK)", ":lang_id" =&gt; 1 ) ;
</code></pre>

<p>and then execute it</p>

<pre><code>$stmt-&gt;execute(array($query_array));
</code></pre>

<p>it wont work, I get </p>

<blockquote>
  <p>Notice: Array to string conversion<code>referring to</code>$stmt->execute(array($query_array));</p>
</blockquote>

<p>and <code>Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number'</code> referring to the same line. </p>

<p>Then I tried to use <strong><code>bindParam</code> to bind the values</strong></p>

<pre><code>$stmt-&gt;bindParam(':lang_alias', $a);
$stmt-&gt;bindParam(':lang_name', $c);
$stmt-&gt;bindParam(':lang_id', $d3, PDO::PARAM_INT);
</code></pre>

<p>and works fine</p>

<p>If I try an <strong>alternative <code>bindParam</code> syntax</strong></p>

<p><code>$stmt-&gt;bindParam("sssiii", $a, $b, $c, $d1, $d2, $d3);</code> </p>

<p>it wont work. Gives</p>

<blockquote>
  <p>Warning: PDOStatement::bindParam() expects at most 5 parameters, 7 given<code>referring to</code>$stmt->bindParam("sssiii", $a, $b, $c, $d1, $d2, $d3);</p>
</blockquote>

<p>and </p>

<blockquote>
  <p>Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 2031 '<code>referring to</code>$stmt->execute();</p>
</blockquote>

<p><strong>1.</strong> Is the error caused by the fact that by default prepared statements convert to string all the values, so I have to define the <code>int</code> by hand?  Thats why the <code>bindParam</code> works fine? Or is it something else that I am missing?</p>

<p><strong>2.</strong> Why the <code>bindParam("sssiii"...</code> sytntax wont work? </p>

<p><strong>3.</strong> I want this query to get its values dynamically, so using a <code>bindParam</code> by hand is not an option. I would like to use an associative array or a <code>bindParam("sssiii"...</code> syntax. </p>

<p>How can I do this? Thanks</p>