jtrw / dao
Data Access Object for fork with DataBases
Installs: 3 266
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 1
Requires
- php: >=7.4
- ext-json: *
- ext-mbstring: *
- ext-pdo: *
Requires (Dev)
- phpunit/phpunit: >=8.0
- squizlabs/php_codesniffer: ^3.0
README
Data Access Object is tiny wrapper on php PDO. There was add more comfortable methods usage conditions in select query.
PDO Usage
<?php $db = new PDO( $GLOBALS['config']['db']['dsn'], $GLOBALS['config']['db']['user'], $GLOBALS['config']['db']['pass'] ); $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); $db->setAttribute(PDO::ATTR_ORACLE_NULLS, PDO::NULL_EMPTY_STRING); $db->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL); $res = $db->query('SET NAMES utf8mb4'); if (!$res) { throw new Exception('Database connection error); } $db = DataAccessObject::factory($db);
Search
$search = [ 'columnName' => 5, 'columnName2&IN' => [1, 2, 3, 4] 'columnName3&<' => 7, 'columnName4&>=' => 3 ]; $sql = "SELECT * FROM users"; $db->select($sql, $search, [], DataAccessObjectInterface::FETCH_ALL)->toNative();
Conditions
Env
make install
make start
make stop
Unittest
php ./vendor/phpunit/phpunit/phpunit -c ./tests/phpunit.xml --testdox --stderr --colors
make tests
- run all tests with migrations
make run-tests
- run all tests without migrations