Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [MySQL][PHP]LIMIT w zapytaniu
Forum PHP.pl > Forum > Przedszkole
Ubermade
Witam! Mam pewien problem z zapytaniem:

  1. $max = isSet( $_GET['max'] ) ? intval( $_GET['max'] ) : 0;


  1. $tbl = $pdo->prepare( 'SELECT * FROM `posts` ORDER BY id DESC LIMIT 0, :limit ' );
  2. $tbl->bindParam(':limit', $max);
  3. $tbl->execute();


i wyskakuje mi taki error:

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'' at line 1 in D:\xampp\htdocs\Webpage\posts.php:166 Stack trace: #0 D:\xampp\htdocs\Webpage\posts.php(166): PDOStatement->execute() #1 {main} thrown in D:\xampp\htdocs\Webpage\posts.php on line 166

Natomiast jeżeli dla przykładu dam
  1. WHERE id = :LIMIT
to wszystko działa
trueblue
  1. $tbl->bindParam(':limit', $max, PDO::PARAM_INT);
Ubermade
Cytat(trueblue @ 17.01.2018, 18:49:03 ) *
  1. $tbl->bindParam(':limit', $max, PDO::PARAM_INT);


Wielkie dzięki, działa biggrin.gif
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.