|
Posted by Sanders Kaufman on 07/24/07 18:44
I'm having a BLAST writing this app as OOP as PHP allows. It's one
thing to discuss the dance, but it's a thing of beauty to see the
performance.
I'm noticing that the constructor is a "reset" switch - just like the
one on the front of my computer. Calling it seems to just dump all of
the old values, free up all of the old resources, and return the object
to a pristine state.
However, I'm a *little* concerned about just using the constructor
willy-nilly like that to reset the object because, several years back, I
had an issue with other programmers who said that my failure to do some
"DIE" commands would result in zombie processes.
The problems never seemed to manifest themselves, but it still caused
the principles to get all up in my grill about it.
Am I setting myself up for zombie processes or other resource-wasting if
I like have a db-connected class and then just BANG reset it with the
constructor. In this particular case, I'm not concerned if "good"
programmers do it this way, but rather - just that I'm not wasting any
resources.
This is the code I use to connect to the database (note the lack of use
of a DIE command):
class bvckvs_database {
//All properties are read-only.
var $Server;
var $DatabaseName;
var $Username;
var $Password;
var $TablePrefix;
var $RecordSQL; // String
var $RecordSet; // Array of Arrays
var $RecordCount; // Integer
var $ErrorMessage; // OK or message
var $oConn; // Database Connection Resource
function bvckvs_database(){
$this->Server=_BVCKVSDBSERVER;
$this->DatabaseName=_BVCKVSDBDATABASE;
$this->Username=_BVCKVSDBUSERNAME;
$this->Password=_BVCKVSDBPASSWORD;
$this->TablePrefix = _BVCKVSUNIQUEPREFIX;
$this->RecordCount = 0;
$this->RecordSet = array();
$this->RecordSQL = "";
$this->ErrorMessage = "OK";
$bVoid = $this->Connect();
}
function Connect(){
$bRetVal = true;
if (!$this->oConn = @mysql_connect($this->Server, $this->Username,
$this->Password)) {
$this->ErrorMessage="Failed to connect to database server.";
$bRetVal = false;
} else {
if (!mysql_selectdb($this->DatabaseName,$this->oConn)) {
$this->ErrorMessage="Failed to select database.";
$bRetVal = false;
} else {
$this->ErrorMessage="OK";
}
}
return $bRetVal;
}
Navigation:
[Reply to this message]
|