PHP code example of haukurh / dbal

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

    

haukurh / dbal example snippets




aukurh\DBAL\DB;
use Haukurh\DBAL\DSN\DSN;

$db = new DB(
    DSN::mysql(
        'example_db',
        'localhost',
        3306,
        'UTF8'
    ),
    'username',
    'password',
);




$contents = [
    'title' => 'Lorem ipsum dolor sit',
    'content' => 'Pellentesque rhoncus dui vitae tincidunt pulvinar...'
];

// Insert a record to the database
$db->insert('articles', $contents);

// Fetch all articles in descending order
$articles = $db->fetchAll('articles', 'ORDER BY id DESC');

// Fetch the next row from a result set
$article = $db->fetch('articles');

// Update records
$db->update('articles', [
    'title' => 'Updated title',
], 'WHERE id = :id', [':id' => 3]);




$articles = $db->fetchAll('articles', 'WHERE id >= :id and title like :term', [
    ':id' => 10,
    ':term' => '%ipsum%',
]);



$id = 10;
$term = '%ipsum%';

$articles = $db->fetchAll('articles', "WHERE id >= {$id} and title like {$term}");