PHPackages                             wp-content-framework/db - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. wp-content-framework/db

ActiveLibrary[Framework](/categories/framework)

wp-content-framework/db
=======================

Wordpress content framework

v1.0.27(5y ago)022.8k2GPL-2.0+PHPPHP &gt;=5.6.0

Since Jan 24Pushed 5y ago1 watchersCompare

[ Source](https://github.com/wp-content-framework/db)[ Packagist](https://packagist.org/packages/wp-content-framework/db)[ Docs](https://github.com/wp-content-framework)[ Fund](https://paypal.me/technote0space)[ RSS](/packages/wp-content-framework-db/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (10)Dependencies (7)Versions (54)Used By (2)

WP Content Framework (DB module)
================================

[](#wp-content-framework-db-module)

[![CI Status](https://github.com/wp-content-framework/db/workflows/CI/badge.svg)](https://github.com/wp-content-framework/db/actions)[![License: GPL v2+](https://camo.githubusercontent.com/ec6306119631a4bc812f4abc1b429674bd65410ae0ef38af01f43483fccc51ce/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d47504c25323076322532422d626c75652e737667)](http://www.gnu.org/licenses/gpl-2.0.html)[![PHP: >=5.6](https://camo.githubusercontent.com/24e105d26965e27afba3dec59eea2ba78bee68047b1762c7be0ba98945ef774e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253345253344352e362d6f72616e67652e737667)](http://php.net/)[![WordPress: >=3.9.3](https://camo.githubusercontent.com/073615bc0d72d97c86c2b3cb3fdbb1f0453a0de432bbe30a48aa8a0d61bec8cf/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f576f726450726573732d253345253344332e392e332d627269676874677265656e2e737667)](https://wordpress.org/)

[WP Content Framework](https://github.com/wp-content-framework/core) のモジュールです。

Table of Contents
-----------------

[](#table-of-contents)

Details- [要件](#%E8%A6%81%E4%BB%B6)
- [インストール](#%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB)
    - [基本設定](#%E5%9F%BA%E6%9C%AC%E8%A8%AD%E5%AE%9A)
- [Author](#author)

要件
==

[](#要件)

- PHP 5.6 以上
- WordPress 3.9.3 以上

インストール
======

[](#インストール)

`composer require wp-content-framework/db`

基本設定
----

[](#基本設定)

- configs/config.php

設定値説明default\_delete\_ruleデフォルトの削除動作を指定（physical or logical \[default = physical\]）- configs/db.php

設定例：

```
// テーブル名 => 設定
'test' => array(

    // primary key 設定
    'id'      => 'test_id',     // optional [default = $table_name . '_id']

    // カラム 設定
    'columns' => array(

        // 論理名 => 設定
        'name'   => array(
            'name'     => 'name_test',     // optional (物理名)
            'type'     => 'VARCHAR(32)',   // required
            'unsigned' => false,           // optional [default = false]
            'null'     => true,            // optional [default = true]
            'default'  => null,            // optional [default = null]
            'comment'  => '',              // optional
        ),
        'value1' => array(
            'type'    => 'VARCHAR(32)',
            'null'    => false,
            'default' => 'test',
        ),
        'value2' => array(
            'type'    => 'VARCHAR(32)',
            'comment' => 'aaaa',
        ),
        'value3' => array(
            'type'    => 'INT(11)',
            'null'    => false,
            'comment' => 'bbb',
        ),
    ),

    // index 設定
    'index'   => array(
        // key index
        'key'    => array(
            'name' => array( 'name' ),
        ),

        // unique index
        'unique' => array(
            'value' => array( 'value1', 'value2' ),
        ),
    ),

    // 論理削除 or 物理削除
    'delete'  => 'logical', // physical or logical [default = physical]

    // コメント
    'comment' => 'test,
),

```

プラグインのバージョンが変更されたとき またはキャッシュを削除することで 自動でテーブルの追加・更新が行われます。
default の途中変更に関しては文字列のみ対応しています。 [詳細](https://github.com/wp-content-framework/db/issues/25#issuecomment-492293617)
データの取得・挿入・更新・削除はLaravelのDB操作と同じように行うことができます。

```
// 取得
$this->table( 'test' )
     ->where_integer_in_raw( 'id', [ 1, 2, 3 ] )
     ->where( 'value1', 'like', 'tes%' )
     ->where( 'created_at', '
