Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As stated in the documentation for <a href="http://www.php.net/manual/en/pdostatement.execute.php"><code>PDOStatement::execute</code></a>:</p> <blockquote> <p><em><strong><code>input_parameters</code></em></strong></p> <blockquote> <p>An array of values with as many elements as there are bound parameters in the SQL statement being executed. All values are treated as <code>PDO::PARAM_STR</code>.</p> </blockquote> </blockquote> <p>For the most part, this goes entirely unnoticed as MySQL's <a href="http://dev.mysql.com/doc/en/type-conversion.html">implicit type conversion</a> handles the rest (but it can cause some undesirable behaviour if MySQL is using a particularly weird connection character set, as converting strings of numbers back to their numeric value might not give the expected result).</p> <p>In your case, MySQL is attempting to execute a <code>LIMIT</code> clause that has string arguments. Whilst it <em>could</em> attempt to resolve that using its implicit type conversion, as it does everywhere else a string appears where an integer should be, <a href="http://sqlfiddle.com/#!2/d41d8/410">it simply doesn't bother</a> and runs off crying instead.</p> <p>So, you need to tell PDO that these particular parameters are integers. Since even PHP doesn't know what type its variables are, I believe the only way to do that is to directly bind them with either <a href="http://www.php.net/manual/en/pdostatement.bindparam.php"><code>PDOStatement::bindParam</code></a> or <a href="http://www.php.net/manual/en/pdostatement.bindvalue.php"><code>PDOStatement::bindValue</code></a> as you are doing (although it isn't <em>strictly</em> necessary to specify the <code>$data_type</code> argument as a simple <code>(int)</code> cast of the <code>$variable</code> gives PHP's otherwise clueless type system enough to work with).</p> <p>As far as the internal method PDO uses to bind parameters to a variable goes, take a look at <a href="https://github.com/php/php-src/blob/master/ext/pdo/pdo_stmt.c#L302"><code>really_register_bound_param()</code></a> (unsurprisingly not exposed to PHP, so you'll be having lots of fun in C).</p> <p>Good luck!</p>
    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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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