tschueller/phpmysqlgrid
Composer 安装命令:
composer require tschueller/phpmysqlgrid
包简介
A flexible MySQL data grid for PHP with support for filtering, sorting, pagination and CRUD operations.
关键字:
README 文档
README
A flexible MySQL data grid library for PHP.
phpMySQLGrid provides a reusable class to display and manage MySQL table data in a grid with filtering, sorting, pagination, and CRUD actions.
Features
- Table rendering with customizable columns
- CRUD modes: view, add, edit, delete
- Field types: text, boolean, lookup, password, selection, multiline text, file
- Sorting, filtering, and pagination
- PDO-based database access (MySQL, MariaDB, SQLite)
- Hook callbacks for add, edit, and delete workflows
- CSS-based styling with included themes
Requirements
- PHP 8.2 or newer
- MySQL-compatible database
Installation
Install with Composer:
composer require tschueller/phpmysqlgrid
Assets (CSS/JS) are not automatically published. Use the provided CLI command from your host project (see Asset Publishing below) to copy them into your web root.:
php vendor/bin/phpmysqlgrid-assets
For development in this repository:
composer install
Upgrade Guide (v0.5 to v1.0)
See the dedicated upgrade guide in docs/upgrade-guide.md.
Simple Example
<?php require_once __DIR__ . '/vendor/autoload.php'; use PhpMySQLGrid\MySQLGrid; session_start(); $grid = new MySQLGrid(); $grid->hostname = '127.0.0.1'; $grid->username = 'root'; $grid->password = 'secret-password'; $grid->database = 'test_db'; $grid->table = 'users'; $grid->primary = 'id'; $grid->name = 'users_grid'; $grid->limit = 10; $grid->columns = array( array('field' => 'id', 'caption' => 'ID', 'can_sort' => true, 'can_filter' => false), array('field' => 'username', 'caption' => 'Username'), array('field' => 'email', 'caption' => 'Email'), array('field' => 'active', 'caption' => 'Active', 'type' => PHPMYSQLGRID_BOOLEAN), ); $grid->execute();
Database Connection Modes
phpMySQLGrid supports two connection modes:
- Default mode (legacy-compatible): internal PDO connection created automatically from
hostname,port,username,password,databaseproperties. - Injected connection mode: externally managed PDO connection via
setDatabaseConnection().
1) Default mode (internal PDO)
Set the connection properties and call execute(). The class creates a PDO connection internally using mysql:host=…;port=…;dbname=…;charset=utf8mb4. This mode is fully backward compatible with existing integrations that set these properties.
$grid = new PhpMySQLGrid\MySQLGrid(); $grid->hostname = "127.0.0.1"; $grid->username = "root"; $grid->password = "secret-password"; $grid->database = "test_db"; $grid->table = "users"; $grid->primary = "id"; $grid->execute();
2) Injected PDO mode
Use this mode when you already manage your DB connection externally or when you want to run integration tests against SQLite.
$pdo = new PDO("mysql:host=127.0.0.1;dbname=test_db;charset=utf8mb4", "root", "secret-password"); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $grid = new PhpMySQLGrid\MySQLGrid(); $grid->setDatabaseConnection($pdo, "pdo_mysql"); $grid->table = "users"; $grid->primary = "id"; $grid->execute();
Notes:
- In injected mode, the provided PDO connection is reused for all database operations.
- In injected mode, the caller owns the connection lifecycle.
- All database operations use PDO exclusively; mysqli is no longer supported.
Demo Page
This repository includes a manual demo page with seeded user data and a persistent SQLite database file.
Start the demo server from the project root:
composer run demo:start
Then open:
http://127.0.0.1:8000/
Notes:
- The demo database is stored at
demo/demo.sqliteand is kept across page loads. - Use
http://127.0.0.1:8000/demo/index.php?reset=1to recreate schema and seed data. - Add/edit/delete/filter/sort can be tested directly in the browser.
Asset Publishing for Host Projects
By default, package assets are not automatically copied into your web root. Publish them from your host project with:
php vendor/bin/phpmysqlgrid-assets
Default target is:
assets/phpmysqlgrid
Override target path with either an argument
php vendor/bin/phpmysqlgrid-assets --target public/assets/phpmysqlgrid
or an environment variable:
# Bash
PHPMYSQLGRID_ASSET_TARGET=public/assets/phpmysqlgrid php vendor/bin/phpmysqlgrid-assets
# PowerShell:
$env:PHPMYSQLGRID_ASSET_TARGET="public/assets/phpmysqlgrid"; php vendor/bin/phpmysqlgrid-assets
Automatic Publishing in a Host Project
In your host project's composer.json, you can run asset publishing automatically after install/update:
{
"scripts": {
"post-install-cmd": [
"@grid-assets:publish"
],
"post-update-cmd": [
"@grid-assets:publish"
],
"grid-assets:publish": [
"php vendor/bin/phpmysqlgrid-assets --target public/assets/phpmysqlgrid"
]
}
}
Include CSS
Use MySQLGridAssets for cache-busted URLs/tags.
The default CSS include is split into:
mysqlgrid-base.cssmysqlgrid-theme-default.css
Recommended default theme usage:
use PhpMySQLGrid\MySQLGridAssets; MySQLGridAssets::configure('/assets/phpmysqlgrid'); echo MySQLGridAssets::cssTagsFor();
Dark theme example:
use PhpMySQLGrid\MySQLGridAssets; MySQLGridAssets::configure('/assets/phpmysqlgrid'); echo MySQLGridAssets::cssTagsFor('dark');
When you use themes, set $grid->cssClass so the grid uses the matching theme scope:
$grid->cssClass = "theme-default"; // or $grid->cssClass = "theme-dark";
Currently available themes:
default(modern)dark(dark mode)light(border-less light design)
For full asset helper documentation (themes, custom themes, cache busting internals, method reference, and legacy/deprecated methods), see docs/assets.md.
Code Quality Checks / Unit Tests
Run all quality checks:
composer run lint
Run checks individually:
composer run lint:syntax
composer run lint:style
composer run lint:static
Run unit tests:
composer run test
Contributing
For contribution details, see CONTRIBUTING.md.
Releasing
For release process details, see releasing.md.
Security
Please report vulnerabilities according to SECURITY.md.
For secure runtime configuration and hardening recommendations, see docs/security-settings.md.
License
tschueller/phpmysqlgrid 适用场景与选型建议
tschueller/phpmysqlgrid 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「php」 「sql」 「datagrid」 「mysql」 「pagination」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 tschueller/phpmysqlgrid 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tschueller/phpmysqlgrid 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 tschueller/phpmysqlgrid 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
Store your language lines in the database, yaml or other sources
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Query filtering in your frontend
A PSR-7 compatible library for making CRUD API endpoints
Database/ORM-agnostic query construction helper
统计信息
- 总下载量: 13
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 35
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-05
