PHP code example of simbiat / db-manager

1. Go to this page and download the library: Download simbiat/db-manager library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

simbiat / db-manager example snippets


\Simbiat\Database\Manage::checkTable(string|array $table, string|array $schema = '');

\Simbiat\Database\Manage::getColumnType(string $table, string $column, string $schema = '');

\Simbiat\Database\Manage::getColumnDescription(string $table, string $column, string $schema = '');

\Simbiat\Database\Manage::isNullable(string $table, string $column, string $schema = '');

\Simbiat\Database\Manage::checkFK(string $table, string $fk, string $schema = '');

\Simbiat\Database\Manage::checkColumn(string $table, string $column, string $schema = '');

\Simbiat\Database\Manage::showOrderedTables(string $schema = '', bool $by_size = false);

\Simbiat\Database\Manage::checkCyclicForeignKeys(?array $tables = null)

['schema' => 'schema_name', 'table' => 'table_name']

\Simbiat\Database\Manage::selectAllDependencies(string $schema, string $table);

\Simbiat\Database\Manage::showCreateTable(string $schema, string $table, bool $no_increment = true, bool $if_not_exist = false, bool $add_use = false);

\Simbiat\Database\Manage::(?string $schema = null, ?string $table = null, bool $nullable_only = false);

array(2) {
    #Name of the constraint
    ["test__multiple_constraint"]=>
    array(9) {
        #Table where the constraint is set (with its schema)
        ["child_table"]=>
        string(32) "`simbiatr_simbiat`.`test__child`"
        #Table the constraint is dependent on
        ["parent_table"]=>
        string(33) "`simbiatr_simbiat`.`test__parent`"
        #Value of `DELETE_RULE`
        ["on_delete"]=>
        string(7) "CASCADE"
        #Columns that are used in the constraint with their respective linkage
        ["columns"]=>
        array(2) {
            [0]=>
            array(2) {
                ["child"]=>
                string(12) "parentid_alt"
                ["parent"]=>
                string(2) "id"
            }
            [1]=>
            array(2) {
                ["child"]=>
                string(4) "type"
                ["parent"]=>
                string(4) "type"
            }
        }
        #Generated query you can run to get the values of the violations
        ["select"]=>
        string(333) "SELECT `child`.`parentid_alt`, `child`.`type` FROM `simbiatr_simbiat`.`test__child` AS `child` LEFT JOIN `simbiatr_simbiat`.`test__parent` AS `parent` ON `child`.`parentid_alt` <=> `parent`.`id` AND `child`.`type` <=> `parent`.`type` WHERE (`child`.`parentid_alt` IS NOT NULL OR `child`.`type` IS NOT NULL) AND `parent`.`id` IS NULL;"
        #Generated query that can be run to fix the violations by setting them to `NULL`
        ["update"]=>
        string(446) "UPDATE `simbiatr_simbiat`.`test__child` SET `parentid_alt`=NULL, `type`=NULL WHERE (`parentid_alt`, `type`) IN (SELECT `child`.`parentid_alt`, `child`.`type` FROM `simbiatr_simbiat`.`test__child` AS `child` LEFT JOIN `simbiatr_simbiat`.`test__parent` AS `parent` ON `child`.`parentid_alt` <=> `parent`.`id` AND `child`.`type` <=> `parent`.`type` WHERE (`child`.`parentid_alt` IS NOT NULL OR `child`.`type` IS NOT NULL) AND `parent`.`id` IS NULL);"
        #Generated query that can be run to fix the violations by deleting them
        ["delete"]=>
        string(414) "DELETE FROM `simbiatr_simbiat`.`test__child` WHERE (`parentid_alt`, `type`) IN (SELECT `child`.`parentid_alt`, `child`.`type` FROM `simbiatr_simbiat`.`test__child` AS `child` LEFT JOIN `simbiatr_simbiat`.`test__parent` AS `parent` ON `child`.`parentid_alt` <=> `parent`.`id` AND `child`.`type` <=> `parent`.`type` WHERE (`child`.`parentid_alt` IS NOT NULL OR `child`.`type` IS NOT NULL) AND `parent`.`id` IS NULL);"
        #Number of violations found
        ["count"]=>
        int(1)
    }
    ["test__single_constraint"]=>
    array(9) {
        ["child_table"]=>
        string(32) "`simbiatr_simbiat`.`test__child`"
        ["parent_table"]=>
        string(33) "`simbiatr_simbiat`.`test__parent`"
        ["on_delete"]=>
        string(8) "SET NULL"
        ["columns"]=>
        array(1) {
            [0]=>
            array(2) {
                ["child"]=>
                string(8) "parentid"
                ["parent"]=>
                string(2) "id"
            }
        }
        ["select"]=>
        string(236) "SELECT `child`.`parentid` FROM `simbiatr_simbiat`.`test__child` AS `child` LEFT JOIN `simbiatr_simbiat`.`test__parent` AS `parent` ON `child`.`parentid` <=> `parent`.`id` WHERE (`child`.`parentid` IS NOT NULL) AND `parent`.`id` IS NULL;"
        ["update"]=>
        string(320) "UPDATE `simbiatr_simbiat`.`test__child` SET `parentid`=NULL WHERE (`parentid`) IN (SELECT `child`.`parentid` FROM `simbiatr_simbiat`.`test__child` AS `child` LEFT JOIN `simbiatr_simbiat`.`test__parent` AS `parent` ON `child`.`parentid` <=> `parent`.`id` WHERE (`child`.`parentid` IS NOT NULL) AND `parent`.`id` IS NULL);"
        ["delete"]=>
        string(305) "DELETE FROM `simbiatr_simbiat`.`test__child` WHERE (`parentid`) IN (SELECT `child`.`parentid` FROM `simbiatr_simbiat`.`test__child` AS `child` LEFT JOIN `simbiatr_simbiat`.`test__parent` AS `parent` ON `child`.`parentid` <=> `parent`.`id` WHERE (`child`.`parentid` IS NOT NULL) AND `parent`.`id` IS NULL);"
        ["count"]=>
        int(1)
    }
}

\Simbiat\Database\Manage::fixFKViolations(?string $schema = null, ?string $table = null, bool $nullable_only = true, bool $force_delete = false);

\Simbiat\Database\Manage::rebuildIndexQuery(string $schema, string $table, string $index, bool $run = false);