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.
Related
I have PHP-Solr extension version 1.0.3-alpha installed on my server. I'm initializing the connection using:
$options = array(
'hostname' => 'hostname',
'login' => '',
'password' => '',
'port' => '',
'path' => 'solr/core1');
$client = new SolrClient($options);
It returns the following object:
class SolrClient#17 (1) { private $_hashtable_index => int(13444) }
But whenever I try to run a query like:
$qryArray = 'key_id:123456';
$client->deleteByQuery($qryArray);
It throws an exception as follows:
Solr HTTP Error 7: 'Couldn't connect to server
Can anyone help me to find what would causing this issue?
I have tried var_dump($client->getDebug());, but it returns NULL.
I have a project done with Silex, and I was using herrera-io/silex-pdo as the PDO provider, but I faced random crashes with socket errors (I connect to the DB via socket), since that lib is abandoned, I changed to csanquer/pdo-service-provider, and it works just fine on my localhost server, but when I deploy to remote, I get the following error:
PHP Fatal error: Class 'Csanquer\Silex\PdoServiceProvider\Provider\PdoServiceProvider' not found in /app/web/index.php on line 52
Here is the code around the line 52:
use Csanquer\Silex\PdoServiceProvider\Provider\PdoServiceProvider;
$app->register(
// you can customize services and options prefix with the provider first argument (default = 'pdo')
new PdoServiceProvider('pdo'), // Line 52
array(
'pdo.server' => array(
// PDO driver to use among : mysql, pgsql , oracle, mssql, sqlite, dblib
'driver' => 'mysql',
'host' => 'unix_socket=/app/mysqld.sock',
'dbname' => 'db_beta',
'port' => 3306,
'user' => 'user',
'password' => 'pass',
),
// optional PDO attributes used in PDO constructor 4th argument driver_options
// some PDO attributes can be used only as PDO driver_options
// see http://www.php.net/manual/fr/pdo.construct.php
'pdo.options' => array(
\PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'"
),
// optional PDO attributes set with PDO::setAttribute
// see http://www.php.net/manual/fr/pdo.setattribute.php
'pdo.attributes' => array(
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
),
)
);
Thanks in advance for any help, or any clue of what may be going wrong!
Turns out the problem was with the use instructions. To fix, simply change:
use Csanquer\Silex\PdoServiceProvider\Provider\PdoServiceProvider;
To:
use Csanquer\Silex\PdoServiceProvider\Provider\PDOServiceProvider;
And:
new PdoServiceProvider('pdo') To: new PDOServiceProvider('pdo')
Now it works!
I've installed Laravel-4 and jenssegers / Laravel-MongoDB which has the same interface to Eloquent model as Laravel, so everything is pretty transparent and 1 database connection works OK.
what I'm trying to do, is switch to another database based on user request (Consider it as API that decided where to go and grab data).
This is what I did:
App::before(function($request)
{
$dbPrefix = $request->segment(1);
if (!is_null($dbPrefix)) {
$dbName = strtolower($dbPrefix);
$newDb = DB::connection('mongodb_'.$dbName);
}
});
From here.. I don't know what to do.. Is it connected to new database that way? how do I tell my Laravel to use $newDb when I refer to DB constant in Models?
But I want it to happen before application starts, so specifying "$connection" variable in model or using explicit call to other database like DB::connection('mongodb2')->query(...) is no good for me.
Thanks
The solution to this would be:
/app/filters.php:
App::before(function($request)
{
$dbPrefix = $request->segment(1);
if (!is_null($dbPrefix)) {
$connectionName = 'mongodb_'.strtolower($dbPrefix);
Config::set('database.default', $connectionName);
}
});
/config/database.php:
'mongodb_soccer' => array(
'driver' => 'mongodb',
'host' => 'localhost',
'port' => 27017,
'username' => 'user',
'password' => 'password',
'database' => 'SoccerData'
),
'mongodb_tennis' => array(
'driver' => 'mongodb',
'host' => 'localhost',
'port' => 27017,
'username' => 'user',
'password' => 'password',
'database' => 'TennisData'
)
Requests:
site.com/soccer
will get connection mongodb_soccer
site.com/tennis
will get connection mongodb_tennis
You can pre-authorize it in default "admin" database where your users are stored, and then switch to any database connection per user request to get the actual data.
I needed it this way for API development.
Good luck
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