Download the PHP package haoa/mix-database without Composer

On this page you can find all versions of the php package haoa/mix-database. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package mix-database

mix-database

支持 MySQL、PostgreSQL 的 PDO 查询构建器和协程连接池,提供可选的轻量 Model。

安装

快速开始

以下示例假设已加载 Composer 自动加载文件,并存在相应数据表。 基础 DB 默认使用 PDO::FETCH_OBJ;如需关联数组,通过构造器第四个参数设置 PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC。

并发协程应启用连接池后共享 Database;不能跨并发请求共享查询链、Connection、Transaction 或可变的 Model 实例。未启用连接池时,不要让多个协程并发使用同一个 Database。

创建

查询

更新

删除

PostgreSQL 连接示例(替代上面的 MySQL 连接):

Model 快速示例

Model 必须绑定 Context\Database,不能直接绑定基础 Database。以下示例独立于上面的 $db:

完整用法见 Model 使用指南。

启动连接池 Pool

在 Swoole 协程环境中,启动连接池

连接池统计

创建 Insert

创建

获取 InsertId

替换创建(仅 MySQL;REPLACE 具有替换语义,不等同于普通 UPDATE)

批量创建

使用函数创建

查询 Select

获取结果

方法名称 描述
get(): array 获取多行
first(): array or object or false 获取第一行,无记录返回 false
value(string $field): mixed 获取第一行某个字段
statement(): \PDOStatement 仅能在 debug 回调中读取当前结果集,不作为独立查询终结方法

基础 DB 的 value() 在没有记录或找不到字段时抛出 PDOException;Model 的 value() 无记录时返回 null。

Where

AND

OR

IN

IN 数组逐项绑定,支持与普通参数混用。空数组使用空集子查询;不支持嵌套数组,数组占位符须写为 IN (?) 或 NOT IN (?)。

Select

Order

Limit

Group & Having

Join

更新 Update

更新单个字段

获取影响行数

更新多个字段

使用表达式更新

使用函数更新

删除 Delete

删除

获取影响行数

SQL 安全边界

原生 Raw

事务 Transaction

手动事务

自动事务,执行异常自动回滚并抛出异常

调试 Debug

statement() 也仅在 debug 回调中使用;不要在回调里消费结果集后,又期待外层 get() 返回相同记录。queryLog() 的 sql 与 bindings 是调试依据,插值后的展示 SQL 不应拿来再次执行。

日志 Logger

日志记录器,配置后可打印全部SQL信息

$logger 需实现 Haoa\MixDatabase\LoggerInterface

测试

无数据库测试(不会运行建表及数据初始化):

数据库集成测试会建表及写入数据,配置与运行方式见 测试说明。

License

Apache License Version 2.0, http://www.apache.org/licenses/


All versions of mix-database with dependencies

PHP Build Version
Package Version
Requires php Version >=7.2.0
ext-pdo Version *
haoa/object-pool Version ^1.1
haoa/util Version ^1.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package haoa/mix-database contains the following files

Loading the files please wait ...