GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - yiisoft/db: Yii Database Library

BranchesTags
Open more actions menu

Latest commit

 

History

8,137 Commits
8,137 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
config
config
 
 
docker
docker
 
 
docs
docs
 
 
src
src
 
 
tests
tests
 
 
tools
tools
 
 
.editorconfig
.editorconfig
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
.php-cs-fixer.dist.php
.php-cs-fixer.dist.php
 
 
.phpunit-watcher.yml
.phpunit-watcher.yml
 
 
.roave-backward-compatibility-check.xml
.roave-backward-compatibility-check.xml
 
 
CHANGELOG.md
CHANGELOG.md
 
 
LICENSE.md
LICENSE.md
 
 
Makefile
Makefile
 
 
README.md
README.md
 
 
UPGRADE.md
UPGRADE.md
 
 
composer-dependency-analyser.php
composer-dependency-analyser.php
 
 
composer.json
composer.json
 
 
infection.json.dist
infection.json.dist
 
 
phpunit.xml.dist
phpunit.xml.dist
 
 
psalm.xml
psalm.xml
 
 
rector.php
rector.php
 
 

Repository files navigation

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:

  • Yii DB MSSQL
  • Yii DB MySQL (also supports MariaDB)
  • Yii DB Oracle
  • Yii DB PostgreSQL
  • Yii DB SQLite

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:

  • yiisoft/db-mysql;
  • yiisoft/db-pgsql;
  • yiisoft/db-sqlite;
  • yiisoft/db-mssql;
  • yiisoft/db-oracle.

Tip

To cache database schema information, install PSR-16 implementation. For example, yiisoft/cache or one of the other cache handlers. It's strongly recommended for production.

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' => '[email protected]',
            '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

  • Guide: English, Português - Brasil
  • Internals

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

About

Yii Database Library

www.yiiframework.com/

Topics

databasedbalquery-buildersqlyii3

Resources

Readme
BSD-3-Clause license

Code of conduct

Code of conduct

Contributing

Contributing

Security policy

Security policy
Activity
Custom properties

Stars

215 stars

Watchers

23 watching

Forks

49 forks
Report repository

Releases

Sponsor this project

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.