mariadbphp-7.2

Getting an error when I try to add variable on Query on my php 7 platform


I'm trying add limit & offset as variables on a sql in php application

code looks like this:

$bind[':limit'] = $limit;
$bind[':offset'] = $offset;

$sql= 'SELECT id, monkeys '.
      'from monkeyisland mi ' .
      'left join monkeyland ml '
      'on mi.id = ml.id ' .
      'LIMIT :limit OFFSET :offset ';

$result = $query->run($sql,$bind);

the error message saying:

syntax error check Mariadb server version for the right syntax to use near ''100' OFFSET '0''

is there a different way to right this query variables? Thanks for help in advance


Solution

  • Why are you using bind? you can add the variables directly

    $sql= 'SELECT id, monkeys '.
      'from monkeyisland mi ' .
      'left join monkeyland ml '
      'on mi.id = ml.id ' .
      'LIMIT ' .$limit. ' OFFSET ' .$offset;
    
    $result = $query->run($sql);
    

    The above query should return the same values of the variables!