PHP code example of kaylathedev / dbal

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

    

kaylathedev / dbal example snippets


use DAL\MySQLDatabase;

$db = new MySQLDatabase();

$db->setHost('localhost');
$db->setUsername('admin');
$db->setPassword('secretPA$$w0rd');

$entry = [
    'id' => 1,
    'first_name' => 'George',
    'last_name' => 'Washington',
    'birth_date' => '2/22/1732',
    'death_date' => ''
]
$db->create('presidents', $entry);

use DAL\Condition;

$result = $db->find(Condition::equals('birth_date', '2/22/1732'));
echo $result['last_name'];

$results = $db->findAll(Condition::equals('first_name', 'George'));
foreach ($results as $result) {
    echo $result['birth_date'];
    echo "\n";
}

$entry = [
    'death_date' => '12/14/1799'
]
$db->update('presidents', $entry, Condition::equals('id', 1));

$db->delete('presidents', Condition::equals('id', 1));

$db->delete('presidents'); // Will DELETE EVERY PRESIDENT!