定制 patryknamyslak/patbase 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

patryknamyslak/patbase

最新稳定版本:v2.2.1

Composer 安装命令:

composer require patryknamyslak/patbase

包简介

A highly configurable DB facade and Database interaction interface (Patbase)

README 文档

README

Stop hardcoding database drivers. Patbase provides a clean, type-safe interface for working with any PDO-supported database.

Features

DB Facade - DB Facade + Query builder for faster ship times! \n ✅ 9 Database Drivers - MySQL, PostgreSQL, SQLite, SQL Server, Oracle, and more
Type-Safe - PHP 8.4 enums prevent invalid drivers
Zero Config - Automatic DSN generation and default ports
Lazy Loading - Connect only when needed
Clean API - Fluent, modern PHP interface
Exception Handling - Detailed error messages

Installation

composer require patryknamyslak/patbase

Quick Start

DB Facade + Query Builder

use PatrykNamyslak\Patbase\Facades\DB;
use PatrykNamyslak\Patbase\Enums\WhereOperator;

// SELECT * FROM `blog` WHERE views < :views;
$selectQuery = DB::select([*])->from("blog")->where("views", WhereOperator::LESS_THAN, 500)->all()
// The all() method runs the query by automatically swapping in the parameters in for the value you set in the where part of the chain!


DB::insert()->into("table")->set("title", "New Post title");
DB::upsert(["title"])->into("table")->...;
// OR
DB::insertOrUpdate()
DB::delete()->from("blog")->where("title", WhereOperator::LIKE, "Flag API");

DB::update()->table("table")->...;

Patbase - PDO Abstraction

MySQL

use PatrykNamyslak\Patbase\Patbase;
use PatrykNamyslak\Patbase\Enums\DatabaseDriver;

$db = new Patbase(
    driver: DatabaseDriver::MYSQL,
    database: 'myapp',
    username: 'root',
    password: 'Password123@',
    host: 'localhost',
    port: NULL, // NULL (or omit as the default is NULL) or your custom port, NULL will default to the port based on driver type i.e MYSQL = 3306
);

$users = $db->query("SELECT * FROM `users`;")->fetchAll();

PostgreSQL

$db = new Patbase(
    driver: DatabaseDriver::POSTGRES,
    database: 'myapp',
    username: 'postgres',
    password: 'secret',
    host: 'localhost'
    // port: 5432 (automatic)
);

SQLite

$db = new Patbase(
    driver: DatabaseDriver::SQL_LITE,
    database: './database.db'
    // No username/password needed
);

Prepared Statements

$user = $db->prepare(
    "SELECT * FROM users WHERE email = :email",
    [':email' => 'user@example.com']
)->fetch();

Lazy Loading

// Don't connect yet
$db = new Patbase(
    driver: DatabaseDriver::MYSQL,
    database: 'myapp',
    username: 'root',
    password: 'secret',
    autoConnect: false
);

// Optionally modify DSN
$db->dsn('mysql:host=127.0.0.1;port=3307;dbname=myapp');

// Connect when ready (or auto-connects on first query)
$db->connect();

Supported Databases

Database Driver Enum Default Port
MySQL / MariaDB DatabaseDriver::MYSQL 3306
PostgreSQL DatabaseDriver::POSTGRES 5432
SQLite DatabaseDriver::SQL_LITE N/A (file)
SQL Server DatabaseDriver::MS_SQL_SERVER 1433
SQL Server (Linux) DatabaseDriver::MS_SQL_SERVER_LINUX 1433
Oracle DatabaseDriver::ORACLE 1521
Firebird DatabaseDriver::FIREBIRD 3050
IBM DB2 DatabaseDriver::IBM_DB2 50000
ODBC DatabaseDriver::OPEN_DATABASE_CONNECTIVITY 50000

Advanced Usage

Custom PDO Options

$db = new Patbase(
    driver: DatabaseDriver::MYSQL,
    database: 'myapp',
    username: 'root',
    password: 'secret',
    options: [
        PDO::ATTR_PERSISTENT => true,
        PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8mb4"
    ]
);

Check Connection Status

if (!$db->isConnected()) {
    $db->connect();
}

Access PDO Directly (Advanced)

$pdo = $db->connection();
// Use native PDO methods if needed

License

MIT

Author

Patryk Namyslak - GitHub

AI Notice

This codebase is not written by Artificial intelligence, Only PARTS of the README were generated by Copilot but it used my documented code as reference to make it, so you can say it just turned my scattered documentation into one concise doc.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-07-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固