承接 apex/db 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

apex/db

Composer 安装命令:

composer require apex/db

包简介

Light weight, straight forward DB interface

README 文档

README

A lightweight database layer designed for simplicity and ease of use, providing a middle ground between larger ORMs and base PHP functions (ie. mysqli_*). Supports multiple database engines, object mapping, initialization wrappers for Doctrine and Eloquent, connection load balancing, and an optional wrapper allowing methods to be accessed statically. It supports:

  • Supports mySQL, PostgreSQL, and SQLite with ability to easily implement other engines.
  • Automated mapping to / from objects.
  • Automated preparing of ALL sql queries to protect against SQL injection.
  • Typed, sequential and named placeholders
  • Initialization wrappers for Doctrine and Eloquent
  • Optional secondary read-only connection parameters, which automatically switch to write connection when necessary SQL query is executed.
  • Optional redis support with connection manager allowing both, easy maintainability of connection information across multiple server instances, and multiple read-only connections with automated load balancing via round robin.
  • Command line tool (and PHP class) to easily manage connection information within redis.
  • Optional built-in support for Apex Debugger which will log all SQL queries executed during a request into the debug session for later analysis.
  • Wrapper class allowing methods to be accessed statically for improved efficiency and simplicity.

Installation

Install via Composer with:

composer require apex/db

Table of Contents

  1. Database Connections
  2. SQL Database Methods (26 methods)
    1. insert()
    2. update()
    3. insertOrUpdate()
    4. query()
    5. getRow()
    6. getIdRow()
    7. getObject()
    8. getIdObject()
    9. getField()
    10. getColumn()
    11. getHash()
  3. Placeholders
  4. Object Mapping
  5. Additional / Supplemental
    1. SQL Parser for Large SQL Files
    2. Using redis and the Connection Manager
    3. Utilizing Apex Debugger
    4. Db Wrapper for Statically Accessing Methods
    5. Initialization Wrappers for Doctrine, Eloquent, and PDO

Basic Usage

use Apex\Db\Drivers\mySQL\mySQL;

$db = new mySQL([
    'dbname' => 'mydb', 
    'user' => 'myuser', 
    'password' => 'mydb_password'
]);

// Insert a record
$db->insert('users', [
    'username' => 'jsmith', 
    'full_name' => 'John Smith', 
    'email' => 'jsmith@domain.com'
);
$userid = $db->insertId();

// Get single user by id#
if (!$profile = $db->getIdRow('users', $userid)) { 
    die("No user at id# $userid");
}

// Get single field
if (!$email = $db->getField("SELECT email FROM users WHERE id = %i", $userid)) { 
    die("No e-mail exists for user id# $userid");
}
echo "E-mail is: $email\n";

// Go through all users with @domain.com e-mail
$domain = '@domain.com';
$rows = $db->query("SELECT * FROM users WHERE email LIKE %ls", $domain);
foreach ($rows as $row) { 
    echo "Found: $row[username] - $row[full_name]\n";
}

Object Mapping

Allows mapping to and from objects with ease by simply passing the objects to write methods, and one static call to map results to an object. For example:

use Apex\Db\Drivers\mySQL\mySQL;
use Apex\Db\Mapper\ToInstance;
use MyApp\Models\UserModel;

$db = new mySQL([
    'dbname' => 'mydb', 
    'user' => 'myuser', 
    'password' => 'mydb_password'
]);

// Get users
$rows = $db->"SELECT * FROM users WHERE group_id = 2");
foreach ($rows as $row) {
    $user = ToInstance::map(UserModel::class, $row);
    // $user is a UserModel object, injected and instantiated
}

// Get specific user
$userid = 5811;
$row = $db->getIdRow('users', $userid);    /// $user  is a UserModel object
$user = ToInstance::map(UserModel::class, $row);

// Insert new user
$user = new UserModel($my, $constructor, $params);
$db->insert('users', $user);

// Unsure if inserting or updating?  No problem.
$db->insertOrUpdate('users', $user);

Follow Apex

Loads of good things coming in the near future including new quality open source packages, more advanced articles / tutorials that go over down to earth useful topics, et al. Stay informed by joining the mailing list on our web site, or follow along on Twitter at @mdizak1.

apex/db 适用场景与选型建议

apex/db 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.04k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2021 年 03 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 apex/db 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-03-05