1. Go to this page and download the library: Download kynetcode/wpzylos-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/ */
kynetcode / wpzylos-database example snippets
use WPZylos\Framework\Database\DatabaseServiceProvider;
// In your plugin's boot configuration
'providers' => [
DatabaseServiceProvider::class,
],
use WPZylos\Framework\Database\Connection;
// Resolve from container
$db = $app->make(Connection::class);
// or
$db = $app->make('db');
// Fluent queries via QueryBuilder
$users = $db->table('users')->get();
$user = $db->table('users')->where('id', 1)->first();
// Get all records
$users = $db->table('users')->get();
// Get first record
$user = $db->table('users')->where('email', $email)->first();
// Select specific columns
$names = $db->table('users')->select('id', 'name')->get();
// With conditions
$active = $db->table('users')
->where('status', 'active')
->where('role', 'admin')
->get();
// Comparison operators
$expensive = $db->table('products')
->where('price', '>', 100)
->orderBy('price', 'DESC')
->limit(10)
->get();
// Where IN
$selected = $db->table('users')
->whereIn('id', [1, 2, 3])
->get();
// Count
$total = $db->table('users')
->where('status', 'active')
->count();
// Via QueryBuilder — returns insert ID or false
$id = $db->table('users')->insert([
'name' => 'John Doe',
'email' => '[email protected]',
]);
// Execute raw SQL
$db->query("UPDATE `{$table}` SET views = views + 1 WHERE id = %d", $id);
// Get a single row
$user = $db->getRow("SELECT * FROM `{$table}` WHERE email = %s", $email);
// Get multiple rows
$logs = $db->getResults("SELECT * FROM `{$table}` WHERE level = %s", 'error');
// Get a single value
$count = $db->getVar("SELECT COUNT(*) FROM `{$table}` WHERE status = %s", 'active');