PHPackages                             helmut-kleinhans/yii2-dbtools - 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. [Database &amp; ORM](/categories/database)
4. /
5. helmut-kleinhans/yii2-dbtools

ActiveYii2-extension[Database &amp; ORM](/categories/database)

helmut-kleinhans/yii2-dbtools
=============================

Yii2 Database Backup and Restore functionality

1572JavaScript

Since Jun 25Pushed 7y ago1 watchersCompare

[ Source](https://github.com/helmut-kleinhans/yii2-dbtools)[ Packagist](https://packagist.org/packages/helmut-kleinhans/yii2-dbtools)[ RSS](/packages/helmut-kleinhans-yii2-dbtools/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (2)Used By (0)

\##Check and sync database structure with filesystem and subversion

Database Backup and Restore functionality

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist helmut-kleinhans/yii2-dbtools "*"

```

or add

```
"helmut-kleinhans/yii2-dbtools": "*"

```

to the require section of your `composer.json` file.

Usage
-----

[](#usage)

Once the extension is installed, simply add it in your config by :

Basic `config/web.php`

Advanced `[backend|frontend|common]/config/main.php`

```
    'modules'    => [
        'dbtools' => [
            'class' => 'DbTools\DbToolsModule',
            //'checkDefiner' => 'root@%',       //used for manage tool to show warning if definer of procedure,
                                                //function or trigger definer doesnt match
            //'exportDelimiter' => '$$',        //delimiter which will be used for export of Procedures,Functions
                                                //and Triggers
            //'xmlValues' => '@app/values.xml', //input file for constants and error values
            /*
            //define behaviors for the manage controller
            'behaviorsManage' =>
                [
                'access' => [
                    'class' => \yii\filters\AccessControl::className(),
                    'rules' => [
                        [
                            'allow' => true,
                            'matchCallback' => function ($rule, $action) {
                                return \backend\models\User::checkRoutePermission($action->id,$action->controller->id,$action->controller->module->id);
                            }
                        ],
                    ],
                ],
            ],
            */
        ],
        ...
    ],
    'aliases'    => [
        '@DbToolsExport' => '@app/dbtools',     //folder to save exported and autogenerated files
        ...
    ],

```

Usage
-----

[](#usage-1)

Manage
------

[](#manage)

Pretty Url's `/dbtools/manage`

No pretty Url's `index.php?r=dbtools/manage`

The DbTool interface reads out your database and does some checks.

\###tables Can be saved to filesystem but need to be restored by hand.

- Warnings
    - You can add a Warning by setting a table column comment to "Warning: xxxxx"

\###procedures + functions + triggers Can be saved to filesystem and also be restored.

- Brief Section (see **Brief**)
- Warnings
    - Check-Warnings:
        - if SECURITY TYPE is not INVOKER
        - if DEFINER is not the definer set in config (modules=&gt;dbtools=&gt;checkDefiner)
        - if a DECLARE doesnt start with "m\_" (DECLARE m\_MyVar INT DEFAULT 0 ;)
        - if a DECLARE known ERROR doesnt match the error value / error type
        - if a DECLARE known CONST doesnt match the error value / error type
        - if a DECLARE starts with cConst or cError but is not set in values.xml

\###views Can be saved to filesystem but need to be restored by hand.

\###events Can be saved to filesystem but need to be restored by hand.

#### Brief

[](#brief)

The brief section should be at the top of your procedure/function/trigger

```
CREATE DEFINER=`root`@`%` PROCEDURE `myproc`(
               IN  inVar  INT UNSIGNED,
               OUT outVar BIGINT,
           )
       BEGIN
           /**
           @brief description of myproc
           @param  inVar      description of param1
           @param  outVar     description of param2
           */

           DECLARE  ...

```

- @brief
    - description of this item
- @param \[ParameterName\]
    - description for the given parameter
- @return
    - description of function return value
- @warning \[Warning Message Text\]
    - adds a warning to manage interface
- @note \[Note Text\]
    - adds a note to manage interface
- @deprecated
    - used to mark the item as deprecated and adds a warning
- @todo \[Todo Text\]
    - adds a todo to manage interface
- @export
    - marks the item for autogeneration (see **Autogen**)
- @select Name
    - You must add a "@select Name" for each select your procedure or subprocedures are outputting. Name is used for autogenerated classes to receive results in php (see **Autogen**) (Note: @export will be set to true)

Autogen
-------

[](#autogen)

Pretty Url's `/dbtools/manage/autogen`

No pretty Url's `index.php?r=dbtools/manage/autogen`

The auto generation tool is used to generate PHP files out of input xml (see **values.xml**) and Db procedures/functions (see **Manage**).

### Autogenerated values

[](#autogenerated-values)

You can find an example.xml inside the extension folder

```
values_example.xml

```

Please copy the file to your web folder and set the path inside your config (modules-&gt;dbtools-&gt;xmlValues)

This file is used to generate a php file, which contains user defined constants, errorcodes and also values that get exportet out of db.

The location where the generated file is saved can be set in config (aliases-&gt;@DbToolsExport). The final path will be:

```
@DbToolsExport/dbvalues/DbValues.php

```

Example

```

            Error Message1
            Error Message2

```

Will result in:

```
