Database class advice
Posted: Wed Jun 08, 2005 3:16 pm
I have started to create a database class to reuse in various places. I have taken what I have so far from a couple of classes found on the net. Am I going in the right direction, this only has the connec function in it so far but will eventually contain the fetch rows, last insert functions among others. Comments appreciated.
Code: Select all
<?php
class db {
var $dbLink;
//Constructor
function connect($dbHost, $dbName, $dbUser, $dbPasswd) {
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$starttime = $mtime;
$this->dbLink = mysql_connect ($dbHost, $dbUser, $dbPasswd);
if ( $this->dbLink )
{
if ( $dbName !="" )
{
$this->dbname = $dbName
$dbselect = mysql_select_db ($this->dbName);
if ( !$dbselect )
{
mysql_close( $this->dbLink );
$this->dbLink = $dbselect
}
}
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$endtime = $mtime;
$this->sql_time += $endtime - $starttime;
return $this->dbLink;
}
else
}
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$endtime = $mtime;
$this->sql_time += $endtime - $starttime;
return false;
}
}
?>