Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP][OOP][PDO] Błąd podczas zapytania
Dominator
post
Post #1





Grupa: Zarejestrowani
Postów: 565
Pomógł: 15
Dołączył: 11.10.2010

Ostrzeżenie: (20%)
X----


Nie wiem czemu to się pojawia, pomoże ktoś? Fatal error: Call to undefined method DB::prepare() in index.php on line 5

index.php
  1. <?php
  2.  
  3. include "DBConnection.php";
  4.  
  5. $stmt = $db->prepare("");
  6. $stmt->execute();


DBConnection.php
  1. <?php
  2.  
  3. require 'DB.class.php';
  4.  
  5. try
  6. {
  7. $db = new DB("","","","","");
  8. }
  9. catch(PDOException $e)
  10. {
  11. echo "Error! Code ->".$e->getMessage();
  12. }


Ten post edytował Dominator 29.05.2013, 19:05:55
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Dominator
post
Post #2





Grupa: Zarejestrowani
Postów: 565
Pomógł: 15
Dołączył: 11.10.2010

Ostrzeżenie: (20%)
X----


Na tą potrzebę utworzyłem sobie klasę (IMG:style_emoticons/default/wink.gif)

  1. <?php
  2.  
  3. Class DB
  4. {
  5. public function __construct($server, $port, $username, $password, $database)
  6. {
  7. $this->Set($server, $port, $username, $password, $database);
  8. $this->$database=$this->Connect();
  9. }
  10. protected function Set($server, $port, $username, $password, $database)
  11. {
  12. $this->server = $server;
  13. $this->port = $port;
  14. $this->user = $username;
  15. $this->pass = $password;
  16. $this->database = $database;
  17. }
  18. protected function Connect()
  19. {
  20. $pdo = new PDO('mysql:host='.$this->server.';dbname='.$this->database.';port='.$this->port, $this->user, $this->pass );
  21. $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  22. }
  23. protected $server;
  24. protected $port ;
  25. protected $user;
  26. protected $password;
  27. protected $database;
  28. protected $db;
  29. }
  30.  
  31. ?>
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: 6.10.2025 - 16:14