1. Go to this page and download the library: Download power/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/ */
power / db example snippets
use \Power\DB;
// Non-static
$db = new \Power\mDB('localhost', 'users', 'passwd', 'dbname', 'utf8mb4');
// Select all records from users table
$data = $db->getAll('SELECT * FROM ?n', 'users');
// Static
DB::Init('localhost', 'users', 'passwd', 'dbname', 'utf8mb4');
// Select all records from users table
$data = DB::getAll('SELECT * FROM ?n', 'users');
use \Power\DB;
DB::Init('localhost', 'users', 'passwd', 'dbname', 'utf8mb4');
// Get one row with some id
$id = 5;
DB::getRow('SELECT * FROM `users` WHERE `id`=?i', $id);
// Get all rows
$login = 'tester';
DB::getAll('SELECT * FROM `logs` WHERE `login`=?s', $login);
// Get one value
DB::getOne('SELECT count(*) FROM `users`');
// Insert some data
$table_name = 'logs';
$data = [
'create_date' => DB::pure('now()'), // when you don't need to escape value - use DB::pure method
'login' => 'tester',
'userid' => 5
];
DB::query('INSERT INTO ?n SET ?u', $table_name, $data);
// or user insert method
DB::insert($table_name, $data);
// Get inserted id from last query
echo DB::insertId();
// Update records
DB::update($table_name, $data)
use \Power\DB;
$db1 = DB::Init('localhost', 'users', 'passwd', 'dbname', 'utf8mb4');
$db2 = DB::Init('localhost', 'users1', 'passwd1', 'dbname1', 'utf8mb4');
// Turn on saving statistics
DB::SetSaveStats(true);
// After initializing, first DB is selected for work
// Get associated array with id field as key
DB::getIndCol('id', 'SELECT `id`,`name` FROM `users`');
// Switching to second database
DB::Switch($db2);
// Get all the rows into indexed array
DB::getInd('id', 'SELECT * FROM `users`');
// Get queries statistics
print_r(DB::getStats());
use \Power\DB;
function ErrorHandler($message)
{
die($message);
}
DB::SetErrorHandler('ErrorHandler');
use \Power\DB;
DB::Init('localhost', 'user', 'passwd', 'dbname', 'utf8mb4');
DB::SetErrorLog(__DIR__.'/mysql_error.log');
DB::SetLogSql(__DIR__.'/mysql_sql.log', false);
// Create class and point table name and col names for inserting records
$cache_items = new \DBCacheQuery('item_list', ['id', 'name', 'icon', 'list', 'data_type']);
foreach ($some_data as $data)
{
// Use Add method for each new row
// Make sure, that param array has the same data order as you make in class creation
$cache_items->Add(
[
$data['id'],
$data['name'],
$data['icon'],
$data['list'],
$data['type']
]);
}
// Then use Flush method to send the remaining data from the cache
$cache_items->Flush();
// That's all
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.