login  Naam:   Wachtwoord: 
Registreer je!
 Forum
Zoeken  Regels  Help
Categorieën > Object georiënteerd

[OOPHP] Database connector (Opgelost)

Chilion – 15/03/2010 17:11 (Laatst gewijzigd op 15/03/2010 17:13)
Beste mensen,
Ik ben redelijk nieuw in het OO fenomeen.

Er gaat hier iets fout, maar ik weet niet wat, wie kan mij even een zetje geven?

menu.php
  1. <?php
  2.  
  3. require_once('database.php');
  4. new Database();
  5.  
  6. class Menu
  7. {
  8.  
  9. public $query = 'SELECT * FROM menu';
  10.  
  11. function __construct()
  12. {
  13.  
  14. $result = mysqli_query($link, $this->query);
  15. $menu = mysqli_fetch_array($res);
  16.  
  17. printr($menu);
  18.  
  19. }
  20. }
  21.  
  22. new Menu();
  23.  
  24. ?>



database.php
  1. <?php
  2.  
  3. class Database
  4. {
  5. public $host = "localhost";
  6. public $user = "chilion_oo";
  7. public $pass = "*****";
  8. public $base = "chilion_oo";
  9. public $link = false;
  10.  
  11.  
  12.  
  13. function __construct()
  14. {
  15. $link = mysqli_connect($this->host, $this->user, $this->pass, $this->base);
  16.  
  17. if(!$link){
  18. die('Could not connect to the database. Error:'.mysqli_error($link));
  19. }
  20. else {
  21. print 'Succesfully connected to the database';
  22. }
  23. }
  24.  
  25.  
  26. function disconnect()
  27. {
  28. mysql_close($link);
  29. }
  30.  
  31. }
  32.  
  33.  
  34. ?>



Foutmelding:
Citaat:
Succesfully connected to the database
Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /home/chilion/domains/chilion.nl/public_html/marc/inc/menu.php on line 14

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /home/chilion/domains/chilion.nl/public_html/marc/inc/menu.php on line 15

Fatal error: Call to undefined function printr() in /home/chilion/domains/chilion.nl/public_html/marc/inc/menu.php on line 17

Alvast bedankt!


Pagina:

13 antwoorden

Gesponsorde links

TotempaaltJ – 15/03/2010 17:12 (Laatst gewijzigd op 15/03/2010 17:13)
Wat gebeurt er wel dan? Zo kunnen we natuurlijk niks! Errors?

Overigens is het voor zover ik weet afgeraden om print's en echo's te doen in functies, gebruik liever returns!

Chilion – 15/03/2010 17:13
Ach ja, sorry. Ze staan erbij in 

TotempaaltJ – 15/03/2010 17:15
Hmm, de errors lijken me duidelijk, toch? De laatste nog wel het makkelijkst op te lossen: niet printr, PHP.net: print_r!

Chilion – 15/03/2010 17:18
Ja, dat snap ik ook, het ging eigenlijk om de bovenste 2 :/

En, ze zijn wel duidelijk ja, maar ik denk dat $link niet op die manier kan. $this->link werkt echter ook niet 

Groetsels.

TotempaaltJ – 15/03/2010 17:22 (Laatst gewijzigd op 15/03/2010 17:36)
No wonder: PHP.net: mysqli_connect bestaat niet? Blablabla, negeer dat 

Chilion – 15/03/2010 17:32
Kun je misschien iets duidelijker zijn want ik snap de zak van je reacties

Raze – 15/03/2010 17:34 (Laatst gewijzigd op 15/03/2010 17:34)
TotempaaltJ schreef:
No wonder: PHP.net: mysqli_connect bestaat niet?

Bestaat niet?   http://php.net/manual/en/mysqli.connect.php

lemoinet – 15/03/2010 17:35
  1. <?php
  2.  
  3. require_once('database.php');
  4.  
  5. class Menu
  6. {
  7.  
  8. public $query = 'SELECT * FROM menu';
  9. private $_db;
  10.  
  11. function __construct()
  12. {
  13. $_db = new Database();
  14. $result = mysqli_query($_db->link, $this->query);
  15. $menu = mysqli_fetch_array($result);
  16.  
  17. print_r($menu);
  18.  
  19. }
  20. }
  21.  
  22. new Menu();
  23.  
  24. ?>


TotempaaltJ – 15/03/2010 17:35 (Laatst gewijzigd op 15/03/2010 17:37)
Raze schreef:
[..quote..]
Bestaat niet?   http://php.net/manual/en/mysqli.connect.php
Srry, mijn schuld, negeer mijn reactie En btw, lemoinet heeft het antwoord 

Chilion – 15/03/2010 17:59
Toch krijg ik nog deze foutmelding.

  1. Succesfully connected to the database
  2. Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in /home/chilion/domains/chilion.nl/public_html/marc/inc/menu.php on line 14
  3.  
  4. Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /home/chilion/domains/chilion.nl/public_html/marc/inc/menu.php on line 15


Gesponsorde links


Pagina:

Dit onderwerp is gesloten.
Actieve forumberichten:

© 2002-2012 Sitemasters.be - Regels - Gehost door: Vircon - Laadtijd: 0.133s