1. Go to this page and download the library: Download metarush/data-access 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/ */
metarush / data-access example snippets
$builder = (new \MetaRush\DataAccess\Builder)
->setDsn('mysql:host=localhost;dbname=example') // PDO DSN
->setDbUser('foo')
->setDbPass('bar');
// or just
->setPdo($your_own_pdo);
$dal = $builder->build();
// insert 'foo' in column 'col1' and 'bar' in column 'col2'
$data = [
'col1' => 'foo',
'col2' => 'bar'
];
$lastInsertId = $dal->create('table', $data);
// find value of column 'col2' where 'col1' == 'foo'
$column = $dal->findColumn('table', ['col1' => 'foo'], 'col2');
\print_r($column); // bar
$preparedStatement = 'SELECT * FROM table WHERE x = ? AND y = ?';
$bindParams = ['foo', 'bar'];
$fetchStyle = \PDO::FETCH_BOTH; // See https://www.php.net/manual/en/pdostatement.fetch.php for options. Default: \PDO::FETCH_BOTH
$rows = $dal->query($preparedStatement, $bindParams, $fetchStyle);
\print_r($rows);