| Recommend this page to a friend! | 
|  Download | 
| Info | Example |  Files |  Install with Composer |  Download | Reputation | Support forum | Blog | Links | 
| Ratings | Unique User Downloads | Download Rankings | ||||
|    53% | Total: 302 | All time:  7,398 This week: 36  | ||||
| Version | License | PHP version | Categories | |||
| dao-for-php 1.0.3 | Freely Distributable | 7 | PHP 5, Databases | 
| Description | Author | |
| This class can be use to access data objects in a database using PDO. | 
| 
<?php | 
Abstract class DAO for PDO/MySQL
Class heritage Example
class User extends DAO
{
    public function get_by_id(int $id)
    {
        $sql = 'SELECT * FROM users WHERE id = :id';
        $this->executeGet($sql, ['id' => $id]);
    }
    public function create_user(string $name)
    {
        $sql = 'INSERT INTO users (name) VALUES (:name)';
        $this->execute($sql, ['name' => $name]);
        $this->message('User created successfully!');
    }
}
Get user by id example
$user = new User();
$user->get_by_id(1);
if ($user->result['error']) {
    $error = $user->result['data'];
} else {
    $user_obtained = $user->result['data'][0];
}
Create user example
$user = new User();
$user->create_user('John Doe');
$response = $user->result['data'];
public array $result
protected PDO $con - PDO MySQL connection
protected PDO $query - PDO prepared statement for execution
public void execute(string $query, array $params)
public void executeGet(string $query, array $params)
public void message(string $message)
public void close()
| The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. | 
|  Install with Composer | 
| Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
| 100% | 
 | 
 | 
| User Ratings | ||||||||||||||||||||||||||||||
| 
 | ||||||||||||||||||||||||||||||
| Applications that use this package | 
 If you know an application of this package, send a message to the author to add a link here.
 If you know an application of this package, send a message to the author to add a link here.