davidlienhard/database
最新稳定版本:3.0.6
Composer 安装命令:
composer require davidlienhard/database
包简介
🐘 php library for easy access to databases
关键字:
README 文档
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.
统计信息
- 总下载量: 9.22k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-04-14