View Single Post
Old 08-25-2009, 08:01 PM   #7 (permalink)
Fordi
The Visitor
 
Join Date: Aug 2009
Posts: 2
Thanks: 0
Fordi is on a distinguished road
Default

Quote:
Originally Posted by Karl View Post
PHP Code:
class Database
{
    public function 
__construct() { ... }
    public function 
connect() { ... }
    public function 
query() { ... }
    ...

Something I'll usually do is overload the class name with a function:
PHP Code:
function Database() {
    return 
Database::getInstance();

This, in combination with usually returning an object simplifies instruction chaining (and, as a result, code readability) greatly.

PHP Code:
public function rowCount() {
    return 
Database()
        ->
query('select %s from `%q` LIMIT 1',
            
'count(*) as "count"',
            
$this->table
        
)
        ->
fetchObject()
        ->
count;

Fordi is offline  
Reply With Quote