yiisoft/db 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

yiisoft/db

Composer 安装命令:

composer require yiisoft/db

包简介

Database abstraction layer and query builder

README 文档

README

Yii

Yii Database

Latest Stable Version Total Downloads Build status Code Coverage Mutation testing badge Static analysis type-coverage psalm-level

Framework-agnostic database abstraction layer that provides a set of classes to connect and interact with various database management systems (DBMS) using a unified API, including a powerful query builder.

Available database drivers:

Optional packages that provide additional functionality:

  • Yii Active Record provides an object-oriented interface for working with database tables, similar to ORM frameworks such as Doctrine or Hibernate.
  • Yii DB Migration allows you to manage database schema using migrations.

Requirements

  • PHP 8.1 - 8.5.
  • pdo PHP extension.

Installation

To install yiisoft/db you must install at least one database driver:

Important

It also depends on PSR-16: Common Interface for Caching Libraries and requires the installation of PSR-16 implementation. For example, yiisoft/cache or one of the other cache handlers.

General Usage

To connect to a database, create an instance of the appropriate driver:

use Yiisoft\Db\Sqlite\Connection;
use Yiisoft\Db\Sqlite\Driver;

/**
 * @var Psr\SimpleCache\CacheInterface $cache 
 */

// Creating a database connection
$db = new Connection(
    new Driver('sqlite:memory:'),
    new SchemaCache($cache),
);

You can then use the $db object to execute SQL queries, manage transactions, and perform other database operations. Here are some examples:

use Yiisoft\Db\Connection\ConnectionInterface;

/**
 * @var ConnectionInterface $db
 */

// Query builder
$rows = $db 
    ->select(['id', 'email'])  
    ->from('{{%user}}')  
    ->where(['last_name' => 'Smith'])  
    ->limit(10)  
    ->all();

// Insert
$db->createCommand()
    ->insert(
        '{{%user}}',
         [
            'email' => 'mike@example.com',
            'first_name' => 'Mike',
            'last_name' => 'Smith',
         ],
    )
    ->execute();

// Transaction
$db->transaction(
    static function (ConnectionInterface $db) {
        $db->createCommand()
            ->update('{{%user}}', ['status' => 'active'], ['id' => 1])
            ->execute();
        $db->createCommand()
            ->update('{{%profile}}', ['visibility' => 'public'], ['user_id' => 1])
            ->execute();
    }
)

Documentation

If you need help or have a question, the Yii Forum is a good place for that. You may also check out other Yii Community Resources.

License

The Yii Database is free software. It is released under the terms of the BSD License. Please see LICENSE for more information.

Maintained by Yii Software.

Support the project

Open Collective

Follow updates

Official website Twitter Telegram Facebook Slack

统计信息

  • 总下载量: 506.25k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 189
  • 点击次数: 14
  • 依赖项目数: 52
  • 推荐数: 5

GitHub 信息

  • Stars: 187
  • Watchers: 23
  • Forks: 48
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2018-08-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固