- PHP 5.3 or higher
- from the command line
composer require leoshtika/database
- or updating your composer.json file
{
"require": {
"leoshtika/database": "~1.1"
}
}
<?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>';
}
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!