PHP code example of hadi / database

1. Go to this page and download the library: Download hadi/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/ */

    

hadi / database example snippets


$config = [
    'host' => 'localhost',
    'name' => 'temp',
    'username' => 'root',
    'password' => '',
];

$db = new \Hadi\Database();
$db->connect($config);

$db->disconnect();

$db->query('SELECT * FROM users')->get();

$db->query('SELECT * FROM users')->first();

$db->table('users')->select([
    'field' => ['name', 'username'],
])->first();

$db->table('users')->select([
    'field' => ['name', 'username'],
    'condition' => 'WHERE id > 0',
    'limit' => '0, 10',
    'orderby' => 'name',
    'groupby' => 'name',
])->first();

$db->table('users')->insert(['name' => 'John doe', 'email' => '[email protected]']);

$db->table('users')->insert(
    ['name' => 'John doe', 'email' => '[email protected]'],
    ['email']
);

$db->table('users')->update(
    ['name' => 'John doe', 'email' => '[email protected]'],
    ['id' => 1]
);

$db->table('users')->update(
    ['username' => 'johndoe'],
    'id = 1'
);

$db->table('users')->update(
    ['username' => 'johndoe'],
    ['id' => 4],
    ['username']
);

$db->table('users')->delete(['id' => 4]);