Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [MySQL][PHP] Błąd połączenia PDO (Programowanie obiektowe)
Kerth
post
Post #1





Grupa: Zarejestrowani
Postów: 250
Pomógł: 1
Dołączył: 6.08.2012

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


Cześć,
próbuję zrozumieć co jest źle w poniższym kodzie, że pojawiaja się ostrzeżenia. Co robię źle?
  1. class __construct{
  2. private $host = "localhost";
  3. private $username = "root";
  4. private $password = "pass";
  5. private $database = "database";
  6.  
  7. public function SQLConnection($host, $username, $password, $database){
  8. try{
  9. $db = new PDO('mysql:host='.$host.';dbname='.$database.'', ''.$username.'', ''.$password.'',array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
  10. echo 'Połączenie nawiązane!';
  11. }catch(PDOException $e){
  12. echo 'Połączenie nie mogło zostać utworzone.';
  13. }
  14.  
  15. }


Kod
Warning: Missing argument 1 for __construct::SQLConnection(), called in C:\WebServ\httpd\oop_mvc\index.php on line 12 and defined in C:\WebServ\httpd\oop_mvc\controller\ConfigDatabase.class.php on line 18

Warning: Missing argument 2 for __construct::SQLConnection(), called in C:\WebServ\httpd\oop_mvc\index.php on line 12 and defined in C:\WebServ\httpd\oop_mvc\controller\ConfigDatabase.class.php on line 18

Warning: Missing argument 3 for __construct::SQLConnection(), called in C:\WebServ\httpd\oop_mvc\index.php on line 12 and defined in C:\WebServ\httpd\oop_mvc\controller\ConfigDatabase.class.php on line 18

Warning: Missing argument 4 for __construct::SQLConnection(), called in C:\WebServ\httpd\oop_mvc\index.php on line 12 and defined in C:\WebServ\httpd\oop_mvc\controller\ConfigDatabase.class.php on line 18
Połączenie nawiązane!
Fatal error: Call to a member function query() on a non-object in C:\WebServ\httpd\oop_mvc\controller\ConfigDatabase.class.php on line 28
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 20.08.2025 - 12:31