Ey,
Ik heb een mysql class gemaakt.
Alleen om een of andere reden werkt deze niet.
Hier een beschrijfing hoe ik het hebt
- Include (map
mysql_class.php (hier staan alle functions in)
config.php (connect info, deze gebruikt de mysql class)
header.php (deze include config.php, dus ook automatisch mysql_class.php)
footer.php (onderkant van de website)
in de root staat gewoon 1 bestandje met een stukje text er in.
Het probleem is als volgt:
config.php
Als ik dit al doe krijg ik de volgende error:
Als ik op de oude manier connectie maak:
Dan krijg ik op de index pagina deze melding:
Hier komen de pagina's:
mysql_class.php
en in header.php staat dit kleine stukje php code:
Weet iemand hoe die fout komt en hoe ik deze kan oplossen?
Ik heb een mysql class gemaakt.
Alleen om een of andere reden werkt deze niet.
Hier een beschrijfing hoe ik het hebt
- Include (map
mysql_class.php (hier staan alle functions in)
config.php (connect info, deze gebruikt de mysql class)
header.php (deze include config.php, dus ook automatisch mysql_class.php)
footer.php (onderkant van de website)
in de root staat gewoon 1 bestandje met een stukje text er in.
Het probleem is als volgt:
config.php
PHP:
1
2
3
4
5
6
7
8
9
10
| <?php include_once("mysql_class.php"); $db = new mysql(); $host = "localhost"; $name = "brantjev2008"; $pass = "ditisdaneenlekkerlangwachtwoordietochnietgeldigis"; $db = "brantjev2008"; $db->connect($host,$name,$pass,$db); ?> |
Als ik dit al doe krijg ik de volgende error:
code:
1
| Fatal error: Call to a member function connect() on a non-object in D:\brantje.nl v2.0.0.8\Root\brantje.nl v2.0.0.8\include\config.php on line 9 |
Als ik op de oude manier connectie maak:
PHP:
1
2
| mysql_connect($host,$name,$pass); mysql_select_db($db); |
Dan krijg ik op de index pagina deze melding:
code:
1
| Fatal error: Call to a member function query() on a non-object in D:\brantje.nl v2.0.0.8\Root\brantje.nl v2.0.0.8\include\header.php on line 55 |
Hier komen de pagina's:
mysql_class.php
PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
| class mysql { function connect($host, $name, $pass, $db){ $connection = mysql_connect("$host", "$name", "$pass"); mysql_select_db("$db", $connection); }//ends the connection function function close(){ mysql_close($this->connection); }//ends the close function function fetchrow($query){ $rows = mysql_fetch_row($query); return $rows; } function fetcharray($query){ $array = mysql_fetch_array($query); return $array; } function fetchnum($query){ $num = mysql_num_rows($query); return $num; } function query($sql){ $query = mysql_query($sql) or die(mysql_error()); return $query; }//ends the query function }//ends the class |
en in header.php staat dit kleine stukje php code:
PHP:
1
2
3
4
5
6
7
8
9
| <?php $sql = $db->query("SELECT * from menu"); while($obj = $db->fetcharry($sql)){ $naam = $obj[1]; $link = $objp[2]; echo "$naam<br>"; } ?> |
Weet iemand hoe die fout komt en hoe ik deze kan oplossen?