dev-master
9999999-dev https://github.com/funkjedi/clearpdoClearPDO makes connecting with databases and running queries extremely simple.
MIT
The Requires
- php >=5.3.0
- ext-pdo *
by Tim Robertson
database pdo mysql
ClearPDO makes connecting with databases and running queries extremely simple.
ClearPDO makes connecting with databases and running queries extremely simple., (*1)
ClearPDO extends PDO so all the things you can do with vanilla PDO your can do with ClearPDO. For example:, (*2)
$db = new ClearPDO\PDO("mysql:host=$host;dbname=$database;charset=UTF8", $username, $password); $db->prepare("SELECT * FROM provinces WHERE population > ?"); $db->execute(array(500000)); $provinces = $db->fetchAll();
But you can also use the many convenience methods that ClearPDO provides., (*3)
Creating a MySQL Connect, (*4)
Instead of wasting time manually creating a DSN string you can use the following helper method to create a connection using a configuration array., (*5)
$db = ClearPDO\PDO::createMysqlConnection([ 'host' => 'localhost', 'port' => '3396', 'database' => 'blog', 'username' => 'root', 'password' => '3GwZFRjbGezY', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', ]);
Or alternative using a socket connection., (*6)
$db = ClearPDO\PDO::createMysqlConnection([ 'unix_socket' => '/var/run/mysqld/mysqld.sock', 'database' => 'blog', 'username' => 'root', 'password' => '3GwZFRjbGezY', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', ]);
Using the Select Method, (*7)
$statement = $db->select('SELECT content FROM posts WHERE status = :status', [':status' => 'published']); while ($post = $statement->fetch()) { print $post->content; }
Using the Results Method, (*8)
$posts = $db->results('SELECT content FROM posts WHERE status = :status', [':status' => 'published']); foreach ($posts as $post) { print $post->content; }
Using the Lists Method, (*9)
$posts = $db->lists('SELECT id, content FROM posts WHERE status = :status', [':status' => 'published']); foreach ($posts as $id => $content) { print $content; }
Using the Result Method, (*10)
$post = $db->result('SELECT content FROM posts WHERE id = :id', [':id' => 4]); print $post->content;
Using the Column Method, (*11)
$content = $db->column('SELECT content FROM posts WHERE id = :id', [':id' => 4]); print $content;
Using the Insert Method, (*12)
$db->insert('posts', [ 'status' => 'draft' 'content' => 'Vestibulum dictum, nunc vel pulvinar.', 'created' => new DateTime, ]);
Using the Update Method, (*13)
$data = [ 'status' => 'published', 'updated' => new DateTime, ]; $db->insert('posts', $data, 'id = :postID', [':postID' => 4]);
ClearPDO makes connecting with databases and running queries extremely simple.
MIT
database pdo mysql