EimantasFHQ Posted August 27, 2014 Share Posted August 27, 2014 Hey! So, I don't know if this is the current section, couldn't really decide on what section/board to post it, so .. I've got a code that I got from a friend of mine (it was a gaming website (a game server), but he shut it down, I asked for some scripts, he sent me the whole site ..). I got all other scripts correctly, but I do not know how to get this Last Forum Posts to work (IP.Board). I've got the SEO set up as it should and everything, doesn't work. When I use this <?php $_handlerForum = new mysql("Forum","localhost","*********_fqipb2","*********_fqipb2","password"); $topics = $_handlerForum->fetch("SELECT `tid`,`title`,`last_post`,`title_seo`,`last_poster_name` FROM `topics` ORDER BY `last_post` DESC LIMIT 0,3;",array()); $content = ""; foreach($topics as $topic) { $content .= "<a href='http://website.com/forum/index.php?/topic/".$topic['tid']."-".$topic['title_seo']."' target='_blank'>".$topic['title']."</a><br /> <small class='dim'>".$topic['last_poster_name']." - ".date("H:i F d, Y",$topic['last_post'])."</small><hr style='margin: 5px 0px;' />"; } return $content; return "Under Construction"; ?> I get this error Fatal error: Class 'mysql' not found in /home/***/***/***/public_html/extra/forum.php on line 2 Thought that the problem was "new mysql" (on line 2), so I put in mysql_connect, still get an error. Can anyone help? Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted August 27, 2014 Share Posted August 27, 2014 That mysql class is no standard PHP functionality. It's a custom class which you need to include in your code. Quote Link to comment Share on other sites More sharing options...
EimantasFHQ Posted August 27, 2014 Author Share Posted August 27, 2014 Thank you! Added that line of code, so now it doesn't show any error. But .. blank page. What could be the problem? SEO? Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted August 27, 2014 Share Posted August 27, 2014 What is with the use of return on the lines 13 & 15? return is not used for outputting something to the browser. It is usually used for returning data from a custom defined/callback function. To output something you need to use echo or print Quote Link to comment Share on other sites More sharing options...
EimantasFHQ Posted August 27, 2014 Author Share Posted August 27, 2014 What is with the use of return on the lines 13 & 15? return is not used for outputting something to the browser. It is usually used for returning data from a custom defined/callback function. To output something you need to use echo or print Well, I'm not the one who made the script and I'm not that good at php, so .. :/ Would you be able to .. help me make this script work? Currently, it is <?php class mysql { protected $_name; protected $_hostname; protected $_database; protected $_username; protected $_password; protected $_handle = null; public function __construct($name = null,$hostname = null,$database = null,$username = null,$password = null) { $this->_name = $name; $this->_hostname = $hostname; $this->_database = $database; $this->_username = $username; $this->_password = $password; } public function __call($method, $args){ if (!$this->_handle) $this->connect(); return call_user_func_array(array($this, $method), $args); } function connect() { try { $this->_handle = new PDO("mysql:host={$this->_hostname};dbname={$this->_database}",$this->_username,$this->_password); $this->_handle->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $this->_handle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { $this->error($e->getMessage()); return false; } } function error($error) { $file = fopen(PATH_ROOT."error_log.txt","a"); fwrite($file,date("H:i:s d/m/Y",time()).": ".$error." (".$_SERVER['REMOTE_ADDR'].")\r\n"); fclose($file); } protected function select($query,$array) { if (!$this->_handle) return; try { $statement = $this->_handle->prepare($query); $statement->execute($array); return $statement->fetch(); } catch (PDOException $e) { $this->error($e->getMessage()); return false; } } protected function fetch($query,$array) { if (!$this->_handle) return; try { $statement = $this->_handle->prepare($query); $statement->execute($array); return $statement->fetchAll(); } catch (PDOException $e) { $this->error($e->getMessage()); return false; } } protected function execute($query,$array) { if (!$this->_handle) return; try { $statement = $this->_handle->prepare($query); return $statement->execute($array); } catch (PDOException $e) { $this->error($e->getMessage()); return false; } } protected function exec($query,$array) { if (!$this->_handle) return; try { $statement = $this->_handle->prepare($query); $statement->execute($array); return $statement->rowCount(); } catch (PDOException $e) { $this->error($e->getMessage()); return false; } } } $_handlerForum = new mysql("Forum","localhost","*********_fqipb2","*********_fqipb2","password"); $topics = $_handlerForum->fetch("SELECT `tid`,`title`,`last_post`,`title_seo`,`last_poster_name` FROM `topics` ORDER BY `last_post` DESC LIMIT 0,3;",array()); $content = ""; foreach($topics as $topic) { $content .= "<a href='http://website.com/forum/index.php?/topic/".$topic['tid']."-".$topic['title_seo']."' target='_blank'>".$topic['title']."</a><br /> <small class='dim'>".$topic['last_poster_name']." - ".date("H:i F d, Y",$topic['last_post'])."</small><hr style='margin: 5px 0px;' />"; } return $content; return "Under Construction"; ?> Quote Link to comment Share on other sites More sharing options...
EimantasFHQ Posted August 28, 2014 Author Share Posted August 28, 2014 Anyone ? :/ Quote Link to comment Share on other sites More sharing options...
Solution Ch0cu3r Posted August 28, 2014 Solution Share Posted August 28, 2014 Umm.. I think you have used return by mistake. Change return on the last two lines to echo or print. Quote Link to comment Share on other sites More sharing options...
EimantasFHQ Posted August 28, 2014 Author Share Posted August 28, 2014 Thank you!! 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.