2

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

Fabian
  • 265
  • 1
  • 11

1 Answers1

2

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!

DirWolf
  • 871
  • 6
  • 22