davidlienhard / database
🐘 php library for easy access to databases
Installs: 9 039
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 2
pkg:composer/davidlienhard/database
Requires
- php: ^8.4
- ext-mysqli: ^8.4
- davidlienhard/functioncaller: ^1
Requires (Dev)
- dev-master
- 3.0.6
- 3.0.5
- 3.0.4
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- 2.1.3
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.9
- 2.0.8
- 2.0.7
- 2.0.6
- 2.0.5
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-Update-phpunit/phpunit-requirement-from-10-to-12
- dev-dependabot/composer/phpunit/phpunit-tw-10or-tw-12
- dev-update-readme
- dev-set-default-value-for-fetch_object
- dev-change-composer-requirements-to-php-8.4
- dev-mysqli-unit-tests
This package is auto-updated.
Last update: 2025-11-29 14:16:30 UTC
README
🐘 php library for easy access to databases
Setup
You can install through composer with:
composer require davidlienhard/database:^3
Note: davidlienhard/database requires PHP 8.4
Examples
Connect to the Database-Server
<?php declare(strict_types=1); use DavidLienhard\Database\Exception as DatabaseException; use DavidLienhard\Database\Mysqli; try { $db = new Mysqli; $db->connect("hostname", "username", "password", "dbname"); } catch (DatabaseException $e) { echo "unable to connect to the database host"; exit(1); }
Simple Select Query
<?php declare(strict_types=1); use DavidLienhard\Database\Mysqli; $userResult = $db->query( "SELECT `userID`, `userName` FROM `user`" ); while ($userData = $userResult->fetch_assoc()) { echo $userData['userID'].": ".$userData['userName'].PHP_EOL; }
Select Query with User-Data
<?php declare(strict_types=1); use DavidLienhard\Database\Mysqli; use DavidLienhard\Database\Parameter as DBParam; $userResult = $db->query( "SELECT `userID`, `userName` FROM `user` WHERE `userLevel` = ? and `userType` = ?", new DBParam("i", $userLevel), new DBParam("s", $userType) ); while ($userData = $userResult->fetch_assoc()) { echo $userData['userID'].": ".$userData['userName'].PHP_EOL; }
Insert-Query
<?php declare(strict_types=1); use DavidLienhard\Database\Exception as DatabaseException; use DavidLienhard\Database\Mysqli; use DavidLienhard\Database\Parameter as DBParam; try { $db->query( "INSERT INTO `user` SET `userName` = ?, `userLevel` = ?, `userType` = ?", new DBParam("s", $userName), new DBParam("i", $userLevel), new DBParam("s", $userType) ); } catch (DatabaseException $e) { echo "unable to update table"; exit(1); }
License
The MIT License (MIT). Please see LICENSE for more information.