PHPackages                             pardnchiu/mysql-cli - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. pardnchiu/mysql-cli

ActiveLibrary[Database &amp; ORM](/categories/database)

pardnchiu/mysql-cli
===================

A lightweight MySQL client for PHP featuring intuitive chaining syntax with query builder capabilities and read-write separation.

v1.0.0(8mo ago)42MITPHPPHP &gt;=8.0

Since May 26Pushed 8mo ago1 watchersCompare

[ Source](https://github.com/pardnchiu/php-mysql-cli)[ Packagist](https://packagist.org/packages/pardnchiu/mysql-cli)[ Docs](https://pardn.io)[ RSS](/packages/pardnchiu-mysql-cli/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)DependenciesVersions (5)Used By (0)

MySQL CLI
=========

[](#mysql-cli)

> Lightweight PHP MySQL client with chainable syntax, query builder and read-write separation.
> Following stateless architecture principles, providing stable and reliable database operation experience.

[![packagist](https://camo.githubusercontent.com/b9e20dc3a38a7d82964683844ccd74e1b495fe371f114c21c8a947ae511f8c11/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f706172646e636869752f6d7973716c2d636c69)](https://packagist.org/packages/pardnchiu/mysql-cli)[![version](https://camo.githubusercontent.com/1a9ba833d0716b823ca042cbaa39e31de729617af16f2234a6082372e1596e01/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f7461672f706172646e636869752f7068702d6d7973716c2d636c693f6c6162656c3d72656c65617365)](https://github.com/pardnchiu/php-mysql-cli/releases)[![license](https://camo.githubusercontent.com/9ed99d0b0eed4c7e806af9b70385da1f62289e11a6bd0b1e328b896ab3ba0f54/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f706172646e636869752f7068702d6d7973716c2d636c69)](LICENSE)
[![readme](https://camo.githubusercontent.com/d5091ba395eb4366212f9eba6aeb8e100943733ce395d8fe1670fa047718d214/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f726561646d652d454e2d7768697465)](README.md)[![readme](https://camo.githubusercontent.com/791b697cc57e33a15418cccce06933680ce6a7a4634d3657498fb3a62e573af9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f726561646d652d5a482d7768697465)](README.zh.md)

- [Three Core Features](#three-core-features)
    - [Chainable Syntax](#chainable-syntax)
    - [Read-Write Separation](#read-write-separation)
    - [Stable Connection](#stable-connection)
- [Features](#features)
- [Usage](#usage)
    - [Installation](#installation)
    - [Environment Variables Setup](#environment-variables-setup)
    - [Basic Usage](#basic-usage)
- [API Reference](#api-reference)
    - [Query Builder](#query-builder)
    - [JOIN Operations](#join-operations)
    - [Data Operations](#data-operations)
- [Error Handling](#error-handling)
- [License](#license)
- [Author](#author)

Three Core Features
-------------------

[](#three-core-features)

### Chainable Syntax

[](#chainable-syntax)

Intuitive query builder syntax that makes complex SQL queries simple and readable with low learning curve

### Read-Write Separation

[](#read-write-separation)

Automatically identifies query types and routes to corresponding database connections, supports read-write separation architecture, effectively distributes database load and improves overall system performance

### Stable Connection

[](#stable-connection)

Retry mechanism automatically handles network jitter and temporary connection failures, ensuring reliability in unstable network environments

Features
--------

[](#features)

- **Environment Variable Configuration**: Flexible environment variable settings, supports multi-environment deployment
- **Slow Query Monitoring**: Automatically logs queries over 20ms, assists with performance optimization
- **Secure Parameter Binding**: Prepared statements prevent SQL injection attacks
- **Complete CRUD**: Supports full database operations for create, read, update, delete
- **SQL Function Support**: Built-in common MySQL function recognition and processing
- **Stateless Design**: Independent cleanup for each request

Usage
-----

[](#usage)

### Installation

[](#installation)

```
composer require pardnchiu/mysql-cli
```

### Environment Variables Setup

[](#environment-variables-setup)

#### Read Database (Optional)

[](#read-database-optional)

```
DB_READ_HOST=localhost
DB_READ_PORT=3306
DB_READ_USER=read_user
DB_READ_PASSWORD=read_password
DB_READ_DATABASE=your_database
DB_READ_CHARSET=utf8mb4
```

#### Write Database (Required for write operations)

[](#write-database-required-for-write-operations)

```
DB_WRITE_HOST=localhost
DB_WRITE_PORT=3306
DB_WRITE_USER=write_user
DB_WRITE_PASSWORD=write_password
DB_WRITE_DATABASE=your_database
DB_WRITE_CHARSET=utf8mb4
```

### Basic Usage

[](#basic-usage)

```
