phpBB class that retrieves common tasks
edit the private vars to your settings, this was tested using PHPBB3
<?php
class PHPBB
{
private $phpbb_host = "localhost";
private $phpbb_user = "root";
private $phpbb_pass = "password";
private $phpbb_dbname = "PHPBB";
private $phpbb_prefix = "phpbb_";
protected $phpbb_mysql;
protected $phpbb_table;
function __construct()
{
$this->phpbb_mysql = mysql_connect($this->phpbb_host,$this->phpbb_user,$this->phpbb_pass)
or die(printf('Error connecting to Database: %s',mysql_error()));
mysql_select_db($this->phpbb_dbname,$this->phpbb_mysql);
}
public function allforums()
{
$this->phpbb_change_table("forums");
return $this->phpbb_fetch("select `forum_name` from `$this->phpbb_table`");
}
public function allusers()
{
$this->phpbb_change_table("users");
return $this->phpbb_fetch("select `username` from `$this->phpbb_table");
}
public function close(){ return mysql_close($this->phpbb_mysql); }
public function GetForumID($fname)
{
$this->phpbb_change_table("forums");
$sql=$this->phpbb_fetch("select `forum_id` from `$this->phpbb_table` where `forum_name` = '$fname'");
return $sql[0]['forum_id'];
}
public function GetForumByID($fid)
{
$this->phpbb_change_table("forums");
$sql=$this->phpbb_fetch("select `forum_name` from `$this->phpbb_table` where `forum_id` = '$fid'");
return $sql[0]['forum_name'];
}
public function GetLastPost()
{
$this->phpbb_change_table("posts");
$sql=$this->phpbb_fetch("select `forum_last_poster_name`,`forum_name`,`forum_last_post_time`,`forum_last_post_id` FROM `phpbb_forums` order by `forum_last_post_time` + 0 desc limit 1");
$tname=$this->phpbb_fetch("select `topic_id` from `$this->phpbb_table` where `post_id` = ".$sql[0]['forum_last_post_id']);
$sql[0]['topic_name']=$this->GetTopicByID($tname[0]['topic_id']);
return $sql[0];
}
public function GetTopicByID($tid)
{
$this->phpbb_change_table("topics");
$sql=$this->phpbb_fetch("select `topic_title` from `$this->phpbb_table` where `topic_id` = '$tid'");
return $sql[0]['topic_title'];
}
public function GetUserByID($uid)
{
$this->phpbb_change_table("users");
$sql=$this->phpbb_fetch("select `username` from `$this->phpbb_table` where `user_id` = '$uid'");
return $sql[0]['username'];
}
public function GetUserID($username)
{
$this->phpbb_change_table("users");
$sql=$this->phpbb_fetch("select `user_id` from `$this->phpbb_table` where `username` = '$username'");
return $sql[0]['user_id'];
}
public function phpbb_array_rem($array)
{
foreach($array as $a => $b)
if(!is_numeric($a)) $result[$a]=($b)?$b:"N/A";
return $result;
}
public function phpbb_change_table($newtable){$this->phpbb_table=$this->phpbb_prefix.$newtable;}
public function phpbb_fetch($sql)
{
if(!is_resource($sql))
$sql=mysql_query($sql,$this->phpbb_mysql);
while($row=mysql_fetch_array($sql))
$results[]=$this->phpbb_array_rem($row);
return $results;
}
public function phpbb_query($query){return $this->phpbb_fetch($query);}
}
?>
outside of slightly better and more consistent syntax, this is pretty handy - especially when creating phpBB mods. one thing i would change, phpBB3 has a config.php file that contains all database related configuration; including that file would prevent users from having to declare that information again here.
rated 5/10 for average