PHP code example of websk / php-db

1. Go to this page and download the library: Download websk/php-db 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/ */

    

websk / php-db example snippets




$config = [
    'settings' => [
        'db' => [
            'db_skif' => [
                'host' => 'mysql',
                'db_name' => 'skif',
                'user' => 'root',
                'password' => 'root',
                'dump_file_path' => __DIR__ . '/migrations.sql',
            ],
        ],
    ],
];



use WebSK\DB\DBServiceFactory;

$db_service = DBServiceFactory::factoryMySQL(
    $config['settings']['db']['db_skif']
);



use Psr\Container\ContainerInterface;
use WebSK\DB\DBServiceFactory;

$container->set('DB_SERVICE_CONTAINER_ID', function (ContainerInterface $container) {
    $db_config = $container->get('settings.db.db_skif');

    return DBServiceFactory::factoryMySQL($db_config);
});



use WebSK\DB\DBWrapper;

DBWrapper::setDbService($container->get('DB_SERVICE_CONTAINER_ID'));

$rows = DBWrapper::readAssoc(
    'SELECT id, name FROM users WHERE active = ?',
    [true]
);
bash
composer 
bash
vendor/bin/websk_db_migration.php migrations:migration_auto
vendor/bin/websk_db_migration.php migrations:migration_handle