Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [MySQL][PHP]LIMIT w zapytaniu
Ubermade
post
Post #1





Grupa: Zarejestrowani
Postów: 38
Pomógł: 0
Dołączył: 30.11.2017
Skąd: Leszno, Poland

Ostrzeżenie: (0%)
-----


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
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 2)
trueblue
post
Post #2





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


  1. $tbl->bindParam(':limit', $max, PDO::PARAM_INT);
Go to the top of the page
+Quote Post
Ubermade
post
Post #3





Grupa: Zarejestrowani
Postów: 38
Pomógł: 0
Dołączył: 30.11.2017
Skąd: Leszno, Poland

Ostrzeżenie: (0%)
-----


Cytat(trueblue @ 17.01.2018, 18:49:03 ) *
  1. $tbl->bindParam(':limit', $max, PDO::PARAM_INT);


Wielkie dzięki, działa (IMG:style_emoticons/default/biggrin.gif)
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 22.08.2025 - 13:24