matthewhaworth Posted July 10, 2008 Share Posted July 10, 2008 <?php class db { private $_db; private $_report; private $_querycount = 0; private $_tempquery; function __constructor($report, $db, $user, $pass, $host = 'localhost') { $this->_db = new mysqli($host, $user, $pass, $db); if ($this->_db->connect_errno) { $this->_report->addError('Database connection failed: ' . $this->_db->connect_errno); } else { $this->_report->addNote('Database connection successful.'); } } function query($sql) { if ($this->_tempquery = $this->_db->query($_db, $sql)) { $this->_report->addNote('Query successful.'); $this->_querycount++; return $qry; } else { $this->_report->addError('Query unsuccessful: <br />' . $sql . '<br />' . $this->_db->connect_error); } } function numrows($qry = NULL) { if($qry) { $qry = $this->_tempquery; } return $qry->num_rows; } function fetch($qry = NULL) { if($qry) { $qry = $this->_tempquery; } return $qry->fetch_assoc(); } function multifetch($qry = NULL) { if($qry) { $qry = $this->_tempquery; } $rows = array(); while ($row = $qry->fetch_assoc()) { $rows[] = $row; } return $rows; } } ?> Fatal error: Call to a member function query() on a non-object in C:\apache2triad\htdocs\forum\db.class.php on line 21 if ($this->_tempquery = $this->_db->query($_db, $sql)) { That is the line in question if you can't be bothered counting lol. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted July 10, 2008 Share Posted July 10, 2008 First of all, where is $_db coming from? if ($this->_tempquery = $this->_db->query($_db, $sql)) { Do you mean $this->_db? Also, can I see how you try to call this function? Quote Link to comment Share on other sites More sharing options...
matthewhaworth Posted July 10, 2008 Author Share Posted July 10, 2008 First of all, where is $_db coming from? if ($this->_tempquery = $this->_db->query($_db, $sql)) { Do you mean $this->_db? Also, can I see how you try to call this function? Very good point, it should be $this->$_db. Edit: No, it shouldn't lol, it doesn't need a link parameter, s'me being stupid. The problem seems to be fixed now. However, I'm still getting nothing but white (with errors turned on : P) but that's another problem I should be able to handle myself. Thank you : ]. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted July 10, 2008 Share Posted July 10, 2008 Yeah, I just realized that too. You just need the $sql, correct? Quote Link to comment Share on other sites More sharing options...
matthewhaworth Posted July 10, 2008 Author Share Posted July 10, 2008 Yeah, I just realized that too. You just need the $sql, correct? Aye. I probably read the php.net function definition for the procedural one, without paying much attention. I think they've done a really poor job with the mysqli documentation. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted July 10, 2008 Share Posted July 10, 2008 Did that fix your problem? =P Quote Link to comment Share on other sites More sharing options...
matthewhaworth Posted July 10, 2008 Author Share Posted July 10, 2008 I retract my previous statement, it's still not working with the same error message. <?php //connect to server require("inc.php"); //gather the topics $get_topics_sql = "SELECT topic_id, topic_title, DATE_FORMAT(topic_create_time, '%b %e %Y at %r') aS fmt_topic_create_time, topic_owner FROM forum_topics ORDER BY topic_create_time DESC"; $get_topics_res = $db->query($get_topics_sql); ?> Here is inc.php <?php require("report.class.php"); require("db.class.php"); $report = new report(); $db = new db($report, "forum", "root", "passwordlol"); ?> Quote Link to comment Share on other sites More sharing options...
DarkWater Posted July 10, 2008 Share Posted July 10, 2008 I noticed something else. You never set $this->_report to the $report passed in the constructor. Quote Link to comment Share on other sites More sharing options...
matthewhaworth Posted July 10, 2008 Author Share Posted July 10, 2008 I noticed something else. You never set $this->_report to the $report passed in the constructor. Thank you lol. This is getting embarrassing now lol. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted July 10, 2008 Share Posted July 10, 2008 Did that fix anything? Quote Link to comment Share on other sites More sharing options...
matthewhaworth Posted July 10, 2008 Author Share Posted July 10, 2008 Did that fix anything? Nope : [. Edit: If anybody else read my other thread and has realised that I have corrected the error I had with default parameters incorrectly.. don't worry, I realise it should be "if ($qry == NULL)" now lol. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted July 10, 2008 Share Posted July 10, 2008 Can you post the exact code you have right now? I'll test it on my box. Quote Link to comment Share on other sites More sharing options...
matthewhaworth Posted July 10, 2008 Author Share Posted July 10, 2008 Here is: "db.class.php" <?php class db { private $_db; private $_report; private $_querycount = 0; private $_tempquery; function __constructor($report, $db, $user, $pass, $host = 'localhost') { $this->_db = new mysqli($host, $user, $pass, $db); $this->_report = $report; if ($this->_db->connect_errno) { $this->_report->addError('Database connection failed: ' . $this->_db->connect_errno); } else { $this->_report->addNote('Database connection successful.'); } } function query($sql) { if ($this->_tempquery = $this->_db->query($sql)) { $this->_report->addNote('Query successful.'); $this->_querycount++; return $qry; } else { $this->_report->addError('Query unsuccessful: <br />' . $sql . '<br />' . $this->_db->connect_error); } } function numrows($qry = NULL) { if($qry == NULL) { $qry = $this->_tempquery; } return $qry->num_rows; } function fetch($qry = NULL) { if($qry == NULL) { $qry = $this->_tempquery; } return $qry->fetch_assoc(); } function multifetch($qry = NULL) { if($qry == NULL) { $qry = $this->_tempquery; } $rows = array(); while ($row = $qry->fetch_assoc()) { $rows[] = $row; } return $rows; } } ?> Here is: "report.class.php" <?php class report { private $_userinfo = array(); private $_errors = array(); private $_notes = array(); public function addError($err) { $this->_errors[] = $err; } public function addNote($note) { $this->_notes[] = $note; } public function debug() { $t = "<div name='debug'>"; foreach($this->_userinfo as $userinfo) { $t .= $userinfo; $t .= "<br />"; } foreach($this->_errors as $errors) { $t .= $errors; $t .= "<br />"; } foreach($this->_notes as $notes) $t .= $notes; $t .= "</div>"; return $t; } } ?> Here is: "inc.php" <?php require("report.class.php"); require("db.class.php"); $report = new report(); $db = new db($report, "forum", "root", "passwordlol"); ?> Thank you a LOT for your help so far : ]. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted July 10, 2008 Share Posted July 10, 2008 You might kill yourself, but you named the constructor __constructor instead of __construct. Quote Link to comment Share on other sites More sharing options...
matthewhaworth Posted July 10, 2008 Author Share Posted July 10, 2008 You might kill yourself, but you named the constructor __constructor instead of __construct. Omg. No. Thanks a lot, you've been great. Oh it's embarrassing. have to rush off now anyway lol. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted July 10, 2008 Share Posted July 10, 2008 Ha, any time, took me a while to figure it out too. =) Please mark this topic as solved. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.