Using classes, check this out plz.
Posted: Sun Mar 02, 2003 7:05 pm
Hey guys I have been using classes lately and I recently replaced an old script I was using and used classes.
But I don't want to get into bad habbits I was wondering if I could get this community to take a look at the coding to see if maybe I did something wrong or I did it inefficiently. I don't want to get into any bad habbits. The code is fairly simple.
To see the script in action go to http://www.pcgamemods.com/statcheck.php
db.php
statuscheck.php
statcheck.php
Any suggestions or comments would be appreciated.
But I don't want to get into bad habbits I was wondering if I could get this community to take a look at the coding to see if maybe I did something wrong or I did it inefficiently. I don't want to get into any bad habbits. The code is fairly simple.
To see the script in action go to http://www.pcgamemods.com/statcheck.php
db.php
Code: Select all
<?
class DB
{
var $host = 'localhost';
var $user = 'root';
var $password = '*****';
var $database = 'pcgamemods';
var $conn = NULL;
var $result = false;
function DB($host, $user, $password, $database)
{
$this->host = $host;
$this->user = $user;
$this->password = $password;
$this->database = $database;
}
function open()
{
$this->conn = mysql_pconnect($this->host, $this->user, $this->password);
if (!$this->conn) {
return false;
}
if (@!mysql_select_db($this->database, $this->conn)) {
return false;
}
return true;
}
function close()
{
return (@mysql_close($this->conn));
}
function error()
{
return (mysql_error());
}
function query($sql)
{
$this->result = @mysql_query($sql, $this->conn);
return ($this->result != false);
}
function affectedRows()
{
return (@mysql_affected_rows($this->conn));
}
function numRows()
{
return(@mysql_num_rows($this->result));
}
function fetchObject()
{
return (@mysql_fetch_object($this->result, MYSQL_ASSOC));
}
function fetchArray()
{
return (@mysql_fetch_array($this->result, MYSQL_NUM));
}
function fetchAssoc()
{
return (@mysql_fetch_assoc($this->result));
}
function fetchCount()
{
return (@mysql_fetch_row($this->result));
}
function freeResult()
{
return (@mysql_free_result($this->result));
}
}
?>Code: Select all
<?
class Status
{
var $dl_num;
var $dl_today;
var $dl_downloading;
function Status ()
{
$this->dl_num = $dl_num;
$this->dl_today = $dl_today;
$this->dl_downloading = $dl_downloading;
}
function getdlcount()
{
$db = new DB ('localhost', 'root', '*****', 'pcgamemods');;
$db->open();
$db->query("select count(*) from downloads");
$db->close();
$this->dl_num = $db->fetchCount();
return $this->dl_numї0];
}
function getdlcounttoday($today)
{
$db = new DB ('localhost', 'root', '*****', 'pcgamemods');;
$db->open();
$db->query("select * from dlcount where date = '$today'");
$db->close();
$this->dl_today = $db->fetchAssoc();
return $this->dl_todayїdownloads];
}
function getdownloading($today)
{
$db = new DB ('localhost', 'root', '*****', 'pcgamemods');
$db->open();
$db2 = new DB ('localhost', 'root', '*****', 'pcgamemods');
$db2->open();
$db->query("select * from downloads");
while ($temp = $db->fetchAssoc())
{
$db2->query("select * from core where md5id = '$tempїfile]'");
$this->dl_downloading = $db2->fetchAssoc();
echo $this->dl_downloadingї'name']. '<BR>';
}
}
}
?>Code: Select all
<?
require_once("db.php");
require_once("statuscheck.php");
$today = date("Y-n-d");
$status = new Status;
echo 'Now: <B>' .$status->getdlcount(). '</B><BR>';
echo 'Today: <B>' .$status->getdlcounttoday($today). '</B><BR>';
echo ('<BR><B>Files Being Downloaded:</B><BR>');
echo $status->getdownloading($today);
?>