Page 2 of 2

Posted: Thu Aug 24, 2006 12:05 am
by daedalus__
I don't know. I've kind of been on auto-pilot lately. lol

Posted: Thu Aug 24, 2006 3:05 am
by Jenk
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:

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];
    }
}
in addition to the other parts of you class. :)

Posted: Thu Aug 24, 2006 11:13 am
by daedalus__
Thanks Jenk. :D

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; 
        } 
}
Good, Bad, Ugly? I am figuring since nothing was said that it is an okay way to do that.