Ik ben een beetje aan het expirimenteren met OOP en php ed en nu probeerde ik een database class werkend te krijgen
mysqldb_obj_inc.php
dit is de betreffende class die word gebruikt in
test.php
het enige wat ik hier uit krijg is [Error:] mysql_query failed, toch kan ik niet vinden waarom die failed voor zover ik kan zien klopt alles
ben al een hele dag bezig om uit te vinden wat er niet klopt en of alle variabelen wel kloppen, vandaar die echo's aan het eind.
het ligt niet aan de database, die klopt en werkt en daar zit info in.
kan iemand me verder helpen?
mysqldb_obj_inc.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
| <?php class mysqldb { // set up the object var $host; var $db; var $user; var $password; var $sql; var $numrows; var $connection; // Property Get & Set function gethost() { return $this->host; } function sethost($req_host) { $this->host = $req_host; // ff geknipt in de Get & Set functies omdat ze allemaal ongeveer het zelfde zijn als bovenstaande // Magic functions function mysqldb() { global $mysqlhost, $mysqldatabase, $mysqlusername, $mysqlpassword; $this->sethost($mysqlhost); $this->setdb($mysqldatabase); $this->setuser($mysqlusername); $this->setpassword($mysqlpassword); $this->setconnection(0); } // Methods function openconnection() { $this->dblink = mysql_connect($this->host, $this->user, $this->password); if ($this->connection == 1) { $this->db = mysql_select_db($this->db); $this->setconnection(1); } else { $this->setconnection(0); return false; } return true; } function closeconnection() { if ($this->dbconnection = 1) { mysql_close($this->dblink); } } function selectquery() { if ($this->connection == 0) $this->openconnection(); $this->qry = mysql_query($this->sql); if (!$this->qry) { echo('[Error:] mysql_query failed'); return false; } else { $this->numrows = mysql_num_rows($this->qry); if ($this->numrows > 0) { for($x = 0; $x > $this->numrows; $x++) { $this->result[$x] = mysql_fetch_array($this->qry); } } else { echo('[Error:] mysql_num_rows failed'); return false; } return true; } } } ?> |
dit is de betreffende class die word gebruikt in
test.php
PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| <? include('include/mysqldb_obj_inc.php'); include('include/conf_inc.php'); $db0 = new mysqldb(); $db0->openconnection(); $db0->setsql("SELECT nid,title FROM news_news ORDER BY nid ASC"); $db0->selectquery(); for ($x = 0; $x < count($db0->result); $x++) { echo('<li><a href="?page=home#nid' . $db0->result[$x]['nid'] . '">' . $db0->result[$x]['title'] . '</a></li>'); } echo($db0->result[1]->title); echo($db0->connection); echo($db0->result); echo($db0->qry); ?> |
het enige wat ik hier uit krijg is [Error:] mysql_query failed, toch kan ik niet vinden waarom die failed voor zover ik kan zien klopt alles
ben al een hele dag bezig om uit te vinden wat er niet klopt en of alle variabelen wel kloppen, vandaar die echo's aan het eind.
het ligt niet aan de database, die klopt en werkt en daar zit info in.
kan iemand me verder helpen?
Those who danced were thought to be quite insane by those who could not hear the music.