Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php] bład w klasie do bazy danych
hhg
post 22.07.2007, 15:34:25
Post #1





Grupa: Zarejestrowani
Postów: 316
Pomógł: 0
Dołączył: 5.07.2006

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


robię gdzieś błąd (y) w klasie do bazy danych, proszę o pomoc w poprawkach

  1. <?php
  2.  
  3. class database {
  4.  
  5. var $connection;
  6.  
  7. /* Creates a connection with the database.
  8. @param string: database name
  9. */
  10. function db ($name) {
  11. $this->connection = new mysqli('localhost',$name,'root','');
  12.  
  13. if (mysql_connect_errno()) {
  14. echo '<p class="error">Error: Connection with database ' . $name . ' failed.</p>';
  15. }
  16. }
  17.  
  18.  
  19. /* Executes queries.
  20. @param string: sql query
  21. */
  22. function execute($sql) {
  23. $result = $this->connection->query($sql);
  24.  
  25. return $result;
  26. }
  27.  
  28.  
  29.  
  30. /* Disconnnects with the database.
  31. */
  32. function disconnect() {
  33. $this->connection->close();
  34. }
  35.  
  36.  
  37. }
  38.  
  39.  
  40. $db = new database('comicsite');
  41. $db->execute("SELECT * FROM cms_users");
  42. $db->disconnect();
  43.  
  44.  
  45.  
  46.  
  47. ?>



tresc błędu przy wywołaniu dla linii

  1. <?php
  2. $db->execute("SELECT * FROM cms_users");
  3. ?>


to

Cytat
Fatal error: Call to a member function query() on a non-object in db.class.php on line 23



a dla

  1. <?php
  2. $db->disconnect();
  3. ?>


to


Cytat
Fatal error: Call to a member function close() on a non-object in db.class.php on line 35


Ten post edytował hhg 22.07.2007, 15:36:38
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 Wersja Lo-Fi Aktualny czas: 24.07.2025 - 21:25