Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Błędy w PDO
Robert3d
post
Post #1





Grupa: Zarejestrowani
Postów: 102
Pomógł: 3
Dołączył: 22.04.2006

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


Witam nie rozumiem co się dzieje

Jeżeli całośc wpiszemy ręcznie DZIAŁA
Jeżeli treść zapytania wyglądała by tak ('SELECT :ID FROM test LIMIT 2,2'); DZIAŁA
Ale kod poniższy nie działa (IMG:style_emoticons/default/sad.gif)

  1. <?php
  2.  
  3. $dbh = new PDO('mysql:host=localhost;dbname=test', 'root');
  4. $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  5.  
  6. $stmt = $dbh->prepare('SELECT * FROM test LIMIT :ID,2');
  7. $stmt->execute(array(":ID" => "2"));
  8.  
  9.  
  10. print_r($stmt->fetchAll());
  11.  
  12. ?>
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Robert3d
post
Post #2





Grupa: Zarejestrowani
Postów: 102
Pomógł: 3
Dołączył: 22.04.2006

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


ZAMIENIŁEM ale niestety nadal występuje błąd (IMG:style_emoticons/default/sad.gif)

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''2',2' at line 1' in D:\Program Files\xampp\xampp\htdocs\obiektowo\test2.php:7 Stack trace: #0 D:\Program Files\xampp\xampp\htdocs\obiektowo\test2.php(7): PDOStatement->execute(Array) #1 {main} thrown in D:\Program Files\xampp\xampp\htdocs\test2.php on line 7


  1. $dbh = new PDO('mysql:host=localhost;dbname=test', 'root');
  2. $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  3.  
  4. $stmt = $dbh->prepare('SELECT * FROM test LIMIT :ID,2');
  5. $stmt->execute(array(":ID" => 2));
  6.  
  7.  
  8. print_r($stmt->fetchAll());
  9.  
Go to the top of the page
+Quote Post

Posty w temacie


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: 13.10.2025 - 19:43