Download .zip |
Info | Example | View files (3) | Download .zip | Reputation | Support forum | Blog | Links |
Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
2019-02-11 (7 days ago) | Not enough user ratings | Total: 218 This week: 2 | All time: 8,001 This week: 222 |
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. |
|
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()
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.