1. Go to this page and download the library: Download php-comp/lite-db 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/ */
php-comp / lite-db example snippets
use PhpComp\PdoX\PdoX;
$db = PdoX::create([
// open debug, will record query logs.
'debug' => 1,
'driver' => 'mysql', // 'sqlite' 'pgsql' 'mssql'
'host' => 'localhost',
'user' => 'root',
'password' => 'password',
'database' => 'test',
]);
// add event listeners.
$db->on(PdoX::CONNECT, function ($db) {
echo "connect database success\n";
});
$db->on(PdoX::BEFORE_EXECUTE, function ($sql) {
echo "Will run SQL: $sql\n";
});
$db->on(PdoX::DISCONNECT, function ($db) {
echo "disconnect database success\n";
});
$db->exec('CREATE TABLE IF NOT EXISTS `user` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`username` VARCHAR(32) NOT NULL,
`nickname` VARCHAR(32),
primary key(id)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;');
// fetch all
$ret = $db->fetchAll('show tables');
var_dump($ret);