PHP code example of audinue / sda

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

    

audinue / sda example snippets




udinue\SDA;

$sda = new SDA('sqlite::memory:');

// Begin a transaction
$sda->begin();

// Execute a statement
$sda->exec('CREATE TABLE users (id PRIMARY KEY, password)');

// Ways to pass input parameters
$sda->exec('INSERT INTO users VALUES (?, ?)', 'foo', 'bar');
$sda->exec('INSERT INTO users VALUES (?, ?)', ['baz', 'qux']);
$sda->exec('INSERT INTO users VALUES (:id, :password)', [
	'id' => 'quux',
	'password' => 'zaa'
]);

// Get the last inserted ID
echo $sda->id() . PHP_EOL;

// Get rows
foreach($sda->rows('SELECT * FROM users') as $row) {
	var_dump($row);
}

// Get a row
var_dump($sda->row('SELECT * FROM users WHERE id = ? LIMIT 1', 'bar'));

// Get a cell
echo $sda->cell('SELECT COUNT(*) FROM users') . PHP_EOL;

// Get a column
var_dump($sda->column('SELECT id FROM users'));

// Commit current transaction
$sda->commit();

// Begin another transaction
$sda->begin();

// Another way to inserting row
// INSERT INTO users (id, password) VALUES ('laa', 'laaa')
$sda->insert('users', [
	'id' => 'laa',
	'password' => 'laaa'
]);

// Another way to update a row
// UPDATE users SET password = 'foo' WHERE id = 'foo'
$sda->update('users', [
	'password' => 'foo'
], [
	'id' => 'foo'
]);

// And another way to delete a row
$sda->delete('users', [
	'id' => 'laa'
]);

// Rollback current transaction
$sda->rollback();

// Get the PDO
$pdo = $sda->pdo();