PHP code example of a1phanumeric / php-mysql-class
1. Go to this page and download the library: Download a1phanumeric/php-mysql-class 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/ */
a1phanumeric / php-mysql-class example snippets
use A1phanumeric\DBPDO;
$db = new DBPDO('127.0.0.1', 'app_db', 'app_user', 'secret');
$user = $db->fetch('SELECT id, email FROM users WHERE id = ?', 42);
$db->execute(
'UPDATE users SET email = ? WHERE id = ?',
['[email protected]', 42]
);
$user = $db->fetch('SELECT * FROM users WHERE id = ?', 42);
if ($user === null) {
// Not found or query failed
}
$users = $db->fetchAll('SELECT id, email FROM users WHERE status = ?', 'active');
$usersByEmail = $db->fetchAll('SELECT id, email FROM users', null, 'email');
$db->transaction(function (DBPDO $tx) {
$tx->execute('UPDATE accounts SET balance = balance - ? WHERE id = ?', [100, 1]);
$tx->execute('UPDATE accounts SET balance = balance + ? WHERE id = ?', [100, 2]);
});