Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> mały proble z OOP
rychu123
post
Post #1





Grupa: Zarejestrowani
Postów: 194
Pomógł: 1
Dołączył: 18.09.2008

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


  1. <?php
  2.  
  3. class db
  4. {
  5. private $host;
  6. private $user;
  7. private $pass;
  8. private $db_name;
  9. private $name_tabl;
  10.  
  11. public function __construct($HOST, $USER, $PASS, $DB_NAME, $NAME_TABL)
  12. {
  13. $this->host = $HOST;
  14. $this->user = $USER;
  15. $this->pass = $PASS;
  16. $this->db_name = $DB_NAME;
  17. $this->name_tabl = $NAME_TABL;
  18. }
  19.  
  20. private function connectDb()
  21. {
  22. $conn = new mysqli($this->host, $this->user, $this->pass, $this->db_name);
  23.  
  24. return $conn;
  25. }
  26.  
  27. private function queryTable()
  28. {
  29. return $this->connectDb->query('SELECT * FROM ' . $this->name_tabl);
  30. }
  31.  
  32. public function printNameColums()
  33. {
  34. $finfo = mysqli_fetch_fields($this->queryTable());
  35.  
  36. foreach ($finfo as $val)
  37. {
  38.  
  39. return "<th>" . $val->name . "</th>";
  40. }
  41.  
  42.  
  43. }
  44.  
  45. }
  46.  
  47. $a = new db('localhost', 'root', 'wsk123', 'nauka', 'pracownicy');
  48. echo $a->printNameColums();
  49.  
  50. ?>



Notice: Undefined property: db::$connectDb in C:\xampp\htdocs\ajax\showDb.php on line 29

Fatal error: Call to a member function query() on a non-object in C:\xampp\htdocs\ajax\showDb.php on line 29
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: 24.08.2025 - 00:40