I just installed zend developer tools module and BjyProfiler module in my application. Zend developer tools is working fine and both zend developer tools module and BjyProfiler module showing in module list in toolbar. But BjyProfiler not working properly, when i click database button of zend developers toolbar then it show like following:
I go through BjyProfiler readme in github. After reading readme, I am not sure where to put this code to enable BjyProfiler for query debugging.
$profiler = $sl->get('Zend\Db\Adapter\Adapter')->getProfiler();
$queryProfiles = $profiler->getQueryProfiles();
In summary, my problem is where to put this code and how to enable BjyProfiler successfully to debug query error. Thanks for your kind attention.
Add to aplication.config.php:
'modules' => array(
//...
'BjyProfiler',
'ZendDeveloperTools',
'MyOtherModule',
//...
),
Create bjyprofiler.local.php in config/autoload & add:
$dbParams = array(
'database' => 'ZF2sample',
'username' => 'root',
'password' => '123456',
'hostname' => 'localhost',
// buffer_results - only for mysqli buffered queries, skip for others
'options' => array('buffer_results' => true)
);
return array(
'service_manager' => array(
'factories' => array(
'Zend\Db\Adapter\Adapter' => function ($sm) use ($dbParams) {
$adapter = new BjyProfiler\Db\Adapter\ProfilingAdapter(array(
'driver' => 'pdo',
'dsn' => 'mysql:dbname='.$dbParams['database'].';host='.$dbParams['hostname'],
'database' => $dbParams['database'],
'username' => $dbParams['username'],
'password' => $dbParams['password'],
'hostname' => $dbParams['hostname'],
));
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;
},
),
),
);
F5 in browser!
Related
I have problems with switching a database connection in CakePHP3.
I would like to change the database connection (based on a subdomain, MultiTenant system). But I would like to outsource this connection-change to a plugin.
For this I wrote a small plugin (MTA) with a middleware class, with the following invoke function:
public function __invoke($request, $response, $next)
{
$response = $next($request, $response);
$tenantMap = TableRegistry::get('TenantMappings');
$mapping = $tenantMap->findByName($request->subdomains()[0])->firstOrFail();
ConnectionManager::config("alias_".$request->subdomains()[0], [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
'persistent' => false,
'host' => 'localhost',
'username' => '***username***',
'password' => '***password***',
'database' => '***database***',
'encoding' => 'utf8',
'timezone' => 'UTC',
'cacheMetadata' => true,
]);
ConnectionManager::alias ("alias_".$request->subdomains()[0], "default");
Configure::write('Account.active', $mapping->account_id);
return $response;
}
That does not work. Maybe it is already too late to change the connection or set up an alias.
Is there still a possibility to change the connections for all models in a plugin, or do I have to do this earlier (for example in bootstrap.php)?
That should work fine for all tables that are being instantiated after that point, however you need to move the $next() call (which invokes the next middlware in the queue) to the end of the method, otherwise your code will run after the application request has been completed.
Im creating a Zend APIgility application REST service and having a problem with my fetchAll Mapper function.
I'm connecting to an IBM DB2 database running on an i Series server (AS/400) via DB2 Connect on a Windows Application Server.
My Connection is is made in my local.php as such:
return array(
'db' => array(
'driver' => 'IbmDb2',
'database' => $database,
'username' => $user,
'password' => $password,
'hostname' => $host,
'port' => $port,
'driver_options' => array(
'i5_naming' => DB2_I5_NAMING_ON,
'i5_lib' => 'LIBWEB',
),
),
);
The fetchAll() function in my Mapper class is:
public function fetchAll()
{
$select = new Select('WBRESOURCE');
$paginatorAdapter = new DbSelect($select, $this->adapter);
$collection = new ResourcesCollection($paginatorAdapter);
return $collection;
}
When I hit the DbSelect, ZF2 throws the following DB2 Connect error:
"[IBM][CLI Driver][AS] SQL0204N \"*LIBL.WBRESOURCE\" is an undefined name. SQLSTATE=42704"
Im not sure why its using *LIBL (user defined library list), since I defined the library (SCHEMA) to use as LIBWEB in my connection option.
Thanks in advance!
Rob
Try changing this section:
'driver_options' => array(
'i5_naming' => DB2_I5_NAMING_ON,
'i5_lib' => 'LIBWEB',
Change to":
'driver_options' => array(
'i5_naming' => DB2_I5_NAMING_OFF, <=== change
'i5_lib' => 'LIBWEB',
By using DB2_I5_NAMING_OFF, you should get SQL naming mode. The use of DB2 i5 naming mode will result in things like reliance on a job's library list.
See PHP: db2-connect for some info on the parameter.
i have a 3.* version of solarium installed on cent OS the problem is that the function select of solaruim dos not work and there is no result from it although when i run the same version of solarium on ubuntu is work correctly
$config = array(
'endpoint' => array(
'localhost' => array(
'host' => '127.0.0.1',
'port' => 8983,
'path' => '/solr/',
'core' => 'collection1'
)
)
);
$client3= new Solarium\Client($config);
$query = $client3->createSelect();
$query->setQuery($query_statement);
$query->setFields(array('type_t,book_i,book_name,author,ver_t,publish_t,publishD_t,sub_t,image'));
$query->setRows(100);
at here when i var_dum($query)it work and return an object correctly
enter code here$resultset2 = $client3->select($query);
but when call a select function there is no response var_dum($result2) is empty
$num_found=$resultset2->getNumFound();
this is my code
I'm trying to get the memcache query/result cache working with Oracle. It works flawlessly against mysql (verified with memcached console: ./memcached -u nobody -m 40 -vv). Here's what's in web/index.php:
$servers = array(
'host' => 'localhost',
'port' => 11211,
'persistent' => false
);
$cacheDriver = new Doctrine_Cache_Memcache(array(
'servers' => $servers,
'compression' => false,
'prefix' => 'qc-')
);
$manager = Doctrine_Manager::getInstance();
$manager->setAttribute(Doctrine::ATTR_QUERY_CACHE, $cacheDriver);
$manager->setAttribute(Doctrine::ATTR_RESULT_CACHE, $cacheDriver);
$manager->setAttribute(Doctrine_Core::ATTR_RESULT_CACHE_LIFESPAN, 3600);
This works as supposed against MySQL but fails with following message at the first location where i use ->useResultCache(true):
Result Cache driver not initialized.
Does anyone have clue about what's happening and/or if there's additional configuration needed to get it working with Oracle DB backend?
Thanks.
you should try to set those manager attributes inside your YOUR_APPConfiguration class like explained here : http://www.funstaff.ch/2009/03/19/le-cache-de-resultat-avec-doctrine
class frontendConfiguration extends sfApplicationConfiguration
{
public function configureDoctrine(Doctrine_Manager $manager)
{
$servers = array(
'host' => 'localhost',
'port' => 11211,
'persistent' => false
);
$cacheDriver = new Doctrine_Cache_Memcache(array(
'servers' => $servers,
'compression' => false,
'prefix' => 'qc-')
);
$manager->setAttribute(Doctrine_Core::ATTR_QUERY_CACHE, $cacheDriver);
$manager->setAttribute(Doctrine_Core::ATTR_QUERY_CACHE_LIFESPAN, 3600);
$manager->setAttribute(Doctrine_Core::ATTR_RESULT_CACHE, $cacheDriver);
$manager->setAttribute(Doctrine_Core::ATTR_RESULT_CACHE_LIFESPAN, 3600);
}
}
I can call SQL server 2008 from PHP with Microsoft Drivers for PHP for SQL Server But as Sqlsvr driver class is needed to use CakePHP with SQL server 2008, I got the driver file from following repository.
However, when running my test cakephp with following database.php
<?php
class DATABASE_CONFIG {
var $default = array(
'driver' => 'sqlsvr',
'host' => 'localhost\EPHP',
'login' => 'sa',
'password' => 'xxxxxxx',
'database' => 'Blog',
);
}
?>
I got following error:
Fatal Error (256): ConnectionManager::loadDataSource - Unable to import DataSource class .DboSqlsvr [CORE\cake\libs\model\connection_manager.php, line 185]
Then I have read all the you-cannot-make-cakePHP-work-with-sql-2008 discussions. Is there any resolution by now?
UPDATE: Let me rephrase my question. I would appreciate if someone successfully made CakePHP work with SQL 2008 and tell me the procedure he followed to do that.
After some research, I found this article ( http://book.cakephp.org/view/1652/Plugin-DataSources-and-Datasource-Drivers). Basically, you can not place your driver file in the directory ( \cakephp\cake\libs\model\datasources\dbo) where the "factory" driver files are located. Instead you should place the driver file in following directory of your baked cake.
your-cake-application\plugins\your-plugin-name\models\datasources\dbo
And then you should change your database.php in config accordingly.
<?php
class DATABASE_CONFIG {
var $default = array(
'driver' => 'your-plugin-name.DboSqlsrv',
'host' => 'localhost\EPHP',
'login' => 'sa',
'password' => 'xxxxxxx',
'database' => 'Blog',
);
}
?>
After this, I could run my cakephp app.
Assuming you have the datasources in the folder app/model/datasource/dbo_sqlsrv.php load it like this:
<?php
class DATABASE_CONFIG {
var $default = array(
'datasource' => 'sqlsvr',
'host' => 'localhost\EPHP',
'login' => 'sa',
'password' => 'xxxxxxx',
'database' => 'Blog',
);
}
?>
The difference is in the 'driver' vs 'datasource' keyword