Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [MySQL][PHP]Obiektowe łączenie z bazą danych
brzoza91
post
Post #1





Grupa: Zarejestrowani
Postów: 39
Pomógł: 4
Dołączył: 9.05.2012

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


Witam
Napisałem taki skrypt do łączenia się z bazą danych. Następnie napisałem skrypt testujący lecz wyrzuca mi błąd. Co robię nie tak, bo dopiero zaczynam z programowaniem obiektowym php.

O to błędy:
Warning: mysql_query() expects parameter 2 to be resource, string given in C:\wamp\www\lookbook\class\class.Datebase.php on line 20
mysql_fetch_assoc() expects parameter 1 to be resource, null given in C:\wamp\www\lookbook\class\class.Datebase.php on line 24


  1. class Datebase {
  2.  
  3. private $hConn;
  4. private $dbHost;
  5. private $dbUser;
  6. private $dbPass;
  7. private $dbName;
  8.  
  9. public function _construct() {
  10. $this->dbHost='localhost';
  11. $this->dbName='root';
  12. $this->dbPass='';
  13. $this->dbName='lookbook';
  14.  
  15. $this->hConn = @mysql_connect($this->dbHost,$this->dbName,$this->dbPass);
  16. @mysql_select_db($this->dbName);
  17. }
  18.  
  19. public function select($sql) {
  20. $hRes = mysql_query($this->hConn, $sql);
  21.  
  22.  
  23. $arReturn = array();
  24. while( ($row = mysql_fetch_assoc($hRes)) ) {
  25. $arReturn[] = $row;
  26. }
  27.  
  28. return $arReturn;
  29. }
  30.  
  31. }


  1. require_once("../class/class.Datebase.php");
  2.  
  3.  
  4. $objDB= new Datebase;
  5. $data =$objDB->select("Select * from user");
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: 22.08.2025 - 06:33