Skip to content

Latest commit

 

History

History
77 lines (58 loc) · 1.45 KB

README.md

File metadata and controls

77 lines (58 loc) · 1.45 KB

A lightweight wrapper around PDO

License Packagist

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!