0
Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''0', '1'' at line 1 

There is nothing wrong with my syntax...

$offset = ($current_page__p - 1) * $results_per_page;
    $paginator = new Paginator($query->rowcount, $results_per_page, $current_page__p, $webAddr . "admin-panel/accounts/page/(:num)");
    $query->prepare("SELECT * FROM accounts LIMIT :startz, :resultsPerPage", array(":startz" => $offset,":resultsPerPage" => $results_per_page), true);

Hello, im trying to make a simple pagination. This is the SQL error that i get, im using PDO connection. There is nothing wrong actually with the syntax. The problem comes after the LIMIT part. If i manually type LIMIT 0,1 for example, no problem it works. But when i use bind parameters it doesn't work. I don't use any negative numbers or using reserved words.

I tried every possible way to fix this, no help from google. All other stackoverflow posts talk about reserved words and simple syntax mistakes. In my case, there is no syntax mistake. Also this is the short SQL class that i wrote.

// Fast query class
class query {
    var $result;
    var $rowcount;
    public function prepare ($tmp_sql,$tmp_parameters,$tmp_get_result){
        global $db;
        $stmt = $db->prepare($tmp_sql);
        $stmt->execute($tmp_parameters)or die(print_r($stmt->errorInfo(), true));
        if ($tmp_get_result == true){
            $this->result = $stmt->fetchAll();
            $this->rowcount = $stmt->rowCount();
        }
    }
}
Dlablo
  • 9
  • 1
  • It tells you right away, `SELECT * FROM accounts LIMIT '0', '1'` is not a valid SQL syntax – Your Common Sense Feb 11 '23 at 17:58
  • Well i just said that? I cant bind the parameters like i usually do. When i try to bind the parameters after the LIMIT command i get this error. There is nothing wrong with my syntax. – Dlablo Feb 11 '23 at 18:01
  • But the way, your class can be greatly improved. First of all, right now it's not OOP. You must choose, either you want to use `global` or call your code object-oriented. For the rest, see my article, https://phpdelusions.net/pdo/common_mistakes – Your Common Sense Feb 11 '23 at 18:01
  • `LIMIT` does not allow strings, just numbers. That is, the quotes are the problem. – Rick James Feb 12 '23 at 04:28

0 Answers0