marcocesarato/sqlparser
Composer 安装命令:
composer require marcocesarato/sqlparser
包简介
This class can parse SQL to get query type, tables, field values, etc.. It takes an string with a SQL statements and parses it to extract its different components. Currently the class can extract the SQL query method, the names of the tables involved in the query and the field values that are pas
README 文档
README
Version: 0.2.105 beta
Github: https://github.com/marcocesarato/PHP-Light-SQL-Parser-Class
Author: Marco Cesarato
Description
This class can parse SQL to get query type, tables, field values, etc..
It takes an string with a SQL statements and parses it to extract its different components.
Currently the class can extract the SQL query method, the names of the tables involved in the query and the field values that are passed as parameters. This parser is pretty light respect phpsqlparser or others php sql parser.
Requirements
- php 4+
Install
Composer
- Install composer
- Type
composer require marcocesarato/sqlparser - Enjoy
Usage
$parser = new LightSQLParser("UPDATE Customers AS alias SET ContactName = 'Marco Cesarato', City = 'Milan' WHERE ID = 1;");
OR
$parser = new LightSQLParser(); $parser->setQuery("UPDATE Customers AS alias SET ContactName = 'Marco Cesarato', City = 'Milan' WHERE ID = 1;");
Method
How to retrieve the query's method:
$parser->getMethod();
Output
string(6) "UPDATE"
Tables
How to retrieve the main the query's table:
$parser->getTable();
Output
string(9) "Customers"
How to retrieve the query's tables:
$parser->getAllTables();
Output
array(1) {
[0]=>
string(9) "Customers"
}
Fields
How to retrieve the query's fields:
$parser->getFields();
Output
array(2) {
[0]=>
string(11) "ContactName"
[1]=>
string(4) "City"
}
Methods
LightSQLParser
| Method | Parameters | Description |
|---|---|---|
| __construct | Constructor | |
| setQuery | Set SQL Query string | |
| getQuery | return array | Get SQL Query string |
| getAllQuery | return string | Get SQL All Query string |
| getMethod | param $query return string |
Get SQL Query method |
| getFields | param $query return array |
Get Query fields (at the moment only SELECTINSERTUPDATE) |
| getTable | param $query return string |
Get SQL Query First Table |
| getTables | return array | Get SQL Query Tables |
| getJoinTables | return array | Get SQL Query Join Tables |
| hasJoin | return bool | Return if has join tables |
| getSubQueries | return array | Get all SELECT subqueries |
| hasSubQueries | return bool | Return if has subqueries |
marcocesarato/sqlparser 适用场景与选型建议
marcocesarato/sqlparser 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 46.18k 次下载、GitHub Stars 达 31, 最近一次更新时间为 2019 年 05 月 31 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 marcocesarato/sqlparser 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 marcocesarato/sqlparser 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 46.18k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 31
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2019-05-31