salby / dblyze
dev-master
2018-11-07 14:52 UTC
Requires
- salby/dbee: *
This package is auto-updated.
Last update: 2024-09-08 07:50:58 UTC
README
PHP 的 MySQL 分析库
安装
Dblyze 可以通过 Composer 安装。
$ composer require salby/dblyze
这将把 dblyze 作为项目 vendor/ 目录中的一个依赖项安装。
使用
使用 vendor/ 目录中的自动加载器来加载 dblyze 类。
<?php
// Vendor autoload.
require_once(__DIR__ . '/vendor/autoload.php');
// Initialize the dbee class.
$db = new \salby\dbee\dbee([
'host' => 'localhost',
'database' => 'test',
'user' => 'root',
'password' => ''
]);
// Initialize the dblyze class.
$dblyze = new \salby\dblyze\Dblyze($db);
// Do stuff ...
方法
从表中获取列
$columns = $dblyze -> columns('some_table')
返回 some_table 中所有列的信息。
查找关系
$relations = $dblyze -> relations([
'TABLE_NAME' => 'user',
'COLUMN_NAME' => 'city',
]);
返回与 user.city 相关的所有列。
$relations = $dblyze -> relations([
'REFERENCED_TABLE_NAME' => 'user',
'COLUMN_NAME' => 'id',
]);
返回与 user.id 相关的所有列。
您可以使用的所有搜索参数
- 字符串 TABLE_NAME
- 字符串 COLUMN_NAME
- 字符串 CONSTRAINT_NAME
- 字符串 REFERENCED_TABLE_NAME
- 字符串 REFERENCED_COLUMN_NAME
分析关系表
获取多对多关系中的外表信息,例如 product <- product_category -> category。
$outer_table = $dblyze -> relational_table('product', 'product_category');
返回一个看起来像这样的数组
[
'name' => 'category',
'columns' => [...],
]
... 其中 name 包含外表名称,而 columns 包含在表中找到的列。
获取表的所有信息
文档即将推出。
检查表是否为关系表
文档即将推出。
在表中查找列
文档即将推出。