PHP code example of leoshtika / database

1. Go to this page and download the library: Download leoshtika/database library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

leoshtika / database example snippets



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>';
}



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>';
}