Help with database class design.
Moderator: General Moderators
- daedalus__
- DevNet Resident
- Posts: 1925
- Joined: Thu Feb 09, 2006 4:52 pm
With regards to multiple queries; you can create a method to register the query, then a seperate query to execute all registered queries.
Akin to:in addition to the other parts of you class. 
Akin to:
Code: Select all
class DB
{
private $queries;
private $results;
public function __construct ()
{
$this->queries = array();
$this->results = array();
}
/**
* adds the query to the query bin
* @param sql the query to be added
* @return int the index of the query, which will also be the index of the result.
*/
public function addQuery($sql)
{
$this->queries[] = $sql;
return max(array_keys($this->queries));
}
public function commit ()
{
foreach ($this->queries as $index => $query) {
$this->results[$index] = mysql_query($query);
}
}
public function getResult ($index = 0)
{
return $this->results[$index];
}
}- daedalus__
- DevNet Resident
- Posts: 1925
- Joined: Thu Feb 09, 2006 4:52 pm
Thanks Jenk. 
I was wondering what people think of this:
Good, Bad, Ugly? I am figuring since nothing was said that it is an okay way to do that.
I was wondering what people think of this:
Code: Select all
public function RegisterEntry($entry_type, $entry)
{
switch ($entry_type)
{
case 'error':
$this->errors[count($this->errors)] = $entry;
return count($this->errors)-1;
break;
case 'result':
$this->results[count($this->results)] = $entry;
return count($this->results)-1;
break;
case 'link':
$this->links[count($this->links)] = $entry;
return count($this->links)-1;
break;
default:
throw new Exception('Tried to register unknown or unallowed object!', 0x0f);
break;
}
}