PHP code example of krubio / perfect-database
1. Go to this page and download the library: Download krubio/perfect-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/ */
krubio / perfect-database example snippets
erfectApp\Database\SqliteConnection;
use PerfectApp\Database\MysqlConnection;
// SQLite configuration
$config = [
'path' => 'path/to/database/file',
'options' => [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
],
];
// Create a SQLite connection
$sqliteConnection = new SqliteConnection();
$pdo = $sqliteConnection->connect($config);
// MySQL configuration
$config = [
'host' => 'localhost',
'port' => 3306,
'dbname' => 'my_database',
'charset' => 'utf8mb4',
'username' => 'my_username',
'password' => 'my_password',
'options' => [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
],
];
// Create a MySQL connection
$mysqlConnection = new MysqlConnection();
$pdo = $mysqlConnection->connect($config);
$stmt = $pdo->prepare("SELECT * FROM users WHERE id=:id");
$stmt->bindValue(':id', 1, PDO::PARAM_INT);
$stmt->execute();
$user = $stmt->fetch(PDO::FETCH_ASSOC);