krubio/perfect-database 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

krubio/perfect-database

Composer 安装命令:

composer require krubio/perfect-database

包简介

SOLID Compliant Database Connection

README 文档

README

codecov Build

Coverage Maintainability Rating Code Smells Technical Debt Quality Gate Status Reliability Rating Duplicated Lines (%) Vulnerabilities Bugs Security Rating

Introduction:

These Database Connection Classes are designed to establish a connection with SQLite, MSSQL, Postgres, MongoDB and MySQL databases. These classes provide a common interface for connecting to different databases using PHP Data Objects (PDO) extension This end user documentation and usage instructions will help you to configure and use the SQLiteConnection and MysqlConnection classes in your PHP project.

Installation

You can install the package using Composer. Run the following command in your project directory:

composer require krubio/perfect-database

This will download the package and its dependencies and add the package to your composer.json file.

Usage

Once you have installed the package, you can use the SqliteConnection and MysqlConnection classes by importing them into your code and creating instances of them. Here is an example:

<?php

require_once 'vendor/autoload.php';

use PerfectApp\Database\SqliteConnection;
use PerfectApp\Database\MysqlConnection;

    // SQLite configuration
$config = [
    'path' => 'path/to/database/file',
    'options' => [
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
        PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
    ],
];

// Create a SQLite connection
$sqliteConnection = new SqliteConnection();
$pdo = $sqliteConnection->connect($config);

// MySQL configuration
$config = [
    'host' => 'localhost',
    'port' => 3306,
    'dbname' => 'my_database',
    'charset' => 'utf8mb4',
    'username' => 'my_username',
    'password' => 'my_password',
    'options' => [
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
        PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
    ],
];

// Create a MySQL connection
$mysqlConnection = new MysqlConnection();
$pdo = $mysqlConnection->connect($config);

Note that the vendor/autoload.php file is required to load the classes from the package using Composer's autoloading feature. If you're not using Composer, you'll need to manually include the files for the classes you want to use.

That's it! You can now use the PDO object returned by the connect method to interact with your database.

Example:

$stmt = $pdo->prepare("SELECT * FROM users WHERE id=:id");
$stmt->bindValue(':id', 1, PDO::PARAM_INT);
$stmt->execute();
$user = $stmt->fetch(PDO::FETCH_ASSOC);

Configuration:

To establish a connection with a database using these classes, you need to provide a configuration array with the required parameters. The configuration array must have the following keys:

For SqliteConnection:

  • 'path': The path to the SQLite database file.
  • 'options': An array of PDO options. (optional)

For MysqlConnection:

  • 'host': The MySQL server hostname or IP address.
  • 'port': The MySQL server port number.
  • 'dbname': The name of the MySQL database.
  • 'charset': The character set to use for the connection.
  • 'username': The MySQL username.
  • 'password': The MySQL password.
  • 'options': An array of PDO options. (optional)

Note: The configuration array must contain all the required keys. Otherwise, an InvalidArgumentException will be thrown.

krubio/perfect-database 适用场景与选型建议

krubio/perfect-database 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 811 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 04 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「mongodb」 「mysql」 「sqlite」 「postgresql」 「mssql」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 krubio/perfect-database 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 krubio/perfect-database 我们能提供哪些服务?
定制开发 / 二次开发

基于 krubio/perfect-database 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 811
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 4
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-04-25