leoshtika / database
A lightweight wrapper around PDO
v1.1.2
2016-02-27 15:43 UTC
Requires
- fzaninotto/faker: 1.4.0
- leoshtika/logger: ~1.0
Requires (Dev)
- phpunit/phpunit: ~4.5
This package is not auto-updated.
Last update: 2024-11-09 16:37:43 UTC
README
Requirements
- PHP 5.3 or higher
Installation with Composer
- from the command line
composer require leoshtika/database
- or updating your composer.json file
{
"require": {
"leoshtika/database": "~1.1"
}
}
Usage
Connect to an SQLite database
<?php require_once 'vendor/autoload.php'; use leoshtika\libs\Sqlite; use leoshtika\libs\UserFaker; $sqliteFile = 'demo.sqlite'; // Create the database if not exists UserFaker::create($sqliteFile); $dbh = Sqlite::connect($sqliteFile); $sth = $dbh->prepare('SELECT * FROM user'); $sth->execute(); $users = $sth->fetchAll(PDO::FETCH_ASSOC); foreach ($users as $user) { echo $user['name'] . ' Email: ' . $user['email']; echo '<hr>'; }
Connect to a MySQL database
require_once 'vendor/autoload.php'; use leoshtika\libs\Mysql; $config = array( 'host' => 'localhost', 'dbname' => 'myapp', 'user' => 'root', 'pass' => '', ); $dbh = Mysql::connect($config); $sth = $dbh->prepare('SELECT * FROM user'); $sth->execute(); $users = $sth->fetchAll(PDO::FETCH_ASSOC); foreach ($users as $user) { echo $user['name'] . ' Email: ' . $user['email']; echo '<hr>'; }
Enjoy!