Git Product home page Git Product logo

Comments (2)

bjyoungblood avatar bjyoungblood commented on August 29, 2024

You could do so by essentially copying the config for Zend\Db\Adapter\Adapter and renaming the array keys to something descriptive for your database.

For example:

return array(
    'service_manager' => array(
        'factories' => array(
            'db-master' => function ($sm) use ($dbParams) {
               //setup
            },
            'db-slave' => function ($sm) use ($dbParams) {
              //setup
            }
        )
    )
);

from bjyprofiler.

sarahman avatar sarahman commented on August 29, 2024

Hello, @bjyoungblood .

My configuration files are as follows:

// config/autoload/global.php
<?php return array(
    'db' => array(
        'driver' => 'Pdo',
        'dsn' => 'mysql:dbname=spinfo_blog;host=localhost',
        'username'       => 'root',
        'password'       => '123456',
        //other adapters...
        'adapters' => array(
            'user-db-driver' => array(
                'driver'         => 'Pdo',
                'dsn'            => 'mysql:dbname=spinfo_users;host=localhost',
                'username'       => 'root',
                'password'       => '123456',
            ),
            'image-db-driver' => array(
                'driver'         => 'Pdo',
                'dsn'            => 'mysql:dbname=spinfo_images;host=localhost',
                'username'       => 'root',
                'password'       => '123456',
            )
        )
    ),
    'service_manager' => array(
        'factories' => array(
            'Zend\Db\Adapter\Adapter' => 'Zend\Db\Adapter\AdapterServiceFactory',
        ),
        // to allow other adapters based on the adapters config.
        'abstract_factories' => array(
            'Zend\Db\Adapter\AdapterAbstractServiceFactory'
        )
    )
);

And

<?php
//config/autoload/bjyprofiler.local.php
$prepareAdapter = function($dbParams) {
    $adapter = new BjyProfiler\Db\Adapter\ProfilingAdapter($dbParams);

    if (php_sapi_name() == 'cli') {
        $logger = new Zend\Log\Logger();
        // write queries profiling info to stdout in CLI mode
        $writer = new Zend\Log\Writer\Stream('php://output');
        $logger->addWriter($writer, Zend\Log\Logger::DEBUG);
        $adapter->setProfiler(new BjyProfiler\Db\Profiler\LoggingProfiler($logger));
    } else {
        $adapter->setProfiler(new BjyProfiler\Db\Profiler\Profiler());
    }

    if (isset($dbParams['options']) && is_array($dbParams['options'])) {
        $options = $dbParams['options'];
    } else {
        $options = array();
    }
    $adapter->injectProfilingStatementPrototype($options);
    return $adapter;
};

return array(
    'service_manager' => array(
        'factories' => array(
            'db' => function (\Zend\ServiceManager\ServiceManager $sm) use ($prepareAdapter) {
                $config = $sm->get('Config');
                $dbParams = $config['db'];

                return $prepareAdapter($dbParams);
            },
            'user-db-driver' => function (\Zend\ServiceManager\ServiceManager $sm) use ($prepareAdapter) {
                $config = $sm->get('Config');
                $dbParams = $config['db']['adapters']['user-db-driver'];

                return $prepareAdapter($dbParams);
            },
            'image-db-driver' => function (\Zend\ServiceManager\ServiceManager $sm) use ($prepareAdapter) {
                $config = $sm->get('Config');
                $dbParams = $config['db']['adapters']['image-db-driver'];

                return $prepareAdapter($dbParams);
            }
        ),
    ),
);

But it shows, "You have to install or enable @bjyoungblood's Zend\Db Profiler to use this feature." like this. Please help me use this nice module.

from bjyprofiler.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.