sectoroverload2k/php-mysql-database
最新稳定版本:1.0.21
Composer 安装命令:
composer require sectoroverload2k/php-mysql-database
包简介
PHP Library for OO MySQLi connection and queries
README 文档
README
A lightweight PHP MySQL database wrapper with prepared statement support.
Installation
composer require sectoroverload2k/php-mysql-database
Basic Usage
// Create a new database connection $config = [ 'server' => 'localhost', 'username' => 'username', 'password' => 'password', 'database' => 'database_name' ]; $db = new \PhpMysqlDatabase\Database($config); // Basic query execution $result = $db->query('SELECT * FROM users WHERE active = 1'); // Fetch all results $users = $result->fetchAll(); // Query with parameters using prepared statement $userId = 5; $result = $db->query('SELECT * FROM users WHERE id = ?', [$userId]); $user = $result->fetchAssoc();
Prepared Statements
The library supports fully prepared statements with typed parameter binding.
Basic Prepared Statement
// Prepare statement $stmt = $db->prepare('SELECT * FROM users WHERE username = ? AND status = ?'); // Bind parameters and execute $db->bind_param($stmt, ['john_doe', 'active']); $result = $db->execute($stmt); // Fetch the result $user = $result->fetchAssoc();
Explicitly Defining Parameter Types
// Prepare statement $stmt = $db->prepare('INSERT INTO products (name, price, in_stock) VALUES (?, ?, ?)'); // Bind parameters with explicit types: string, double, integer $db->bind_param($stmt, ['Laptop', 999.99, 10], 'sdi'); $db->execute($stmt); // Get the inserted ID $productId = $db->insert_id();
Parameter Types
When binding parameters, the following type identifiers are available:
i- Integerd- Double (floating-point number)s- Stringb- Blob (binary data)
If you don't specify types, they will be automatically detected based on the PHP variable types.
统计信息
- 总下载量: 148
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-07-11