Have a Zend Framework 2.4 connection factory that needs to establish a connection with an AS400 iSeries database. The connection has to be made this way because there are multiple test environment and the factory needs to accommodate each.
The method is using Zend\Db\Adapter\Adapter and I pass that class an array of database connection parameters.
At issue: Zend\Db\Adapter doesn't accept the relational database (directory) name. I'm assuming that since the driver is PDO_IBM, there would be some expectation of a field for explicitly defining the name for the directory.
Here is the method:
public function conn($dbs) {
$this->adapter = new Adapter(array(
'driver' => $dbs['db']['driver'],
'dbname' => $dbs['db']['dbname'],
'username' => $dbs['db']['username'],
'password' => $dbs['db']['password'],
'hostname' => $dbs['db']['hostname'],
'port' => $dbs['db']['port'],
));
var_dump($this->adapter);
return $this->adapter;
}
Adapter is an alias for \Zend\Db\Adapter\Adapter
And here is the object that gets created.
["driver":protected]=> object(Zend\Db\Adapter\Driver\Pdo\Pdo)#224 (4){
["connection":protected]=>object(Zend\Db\Adapter\Driver\Pdo\Connection)#225 (6) {
["driver":protected]=> *RECURSION*
["profiler":protected]=> NULL
["driverName":protected]=> string(3)"ibm"
["connectionParameters":protected]=> array(6) {
["driver"]=> string(7) "PDO_IBM"
["dbname"]=> string(7) “<relational_database_name>”
["username"]=> string(3) “<user_name"
["password"]=> string(3) “<password>"
["hostname"]=> string(9) "127.0.0.1"
["port"]=> string(3) "446"
}
I can instantiate the connection object using:
$conn = new \Zend\Db\Adapter\Adapter( );
Pdo=ibm:<relational_database_name>
But this isn't a workable solution for this situation. Finally, here is the error:
Connect Error: SQLSTATE=42705, SQLConnect: -950 Relational database dbname=;hos not in relational database directory.
For the sake of completeness, here is the configuration that worked for ZF2 Zend\Db\Adapter\Adapter running on Zend Server 6 and connecting to an AS400 iSeries database.
//concat the driver and rel. db directory name into one string
//$dsn name is required for Zend\Db to correctly read it into memory
$dsn = "ibm:" . $db_dir_name;
$this->adapter = new Adapter(array(
'driver' => $driver, // Pdo
'dsn' => $dsn,
'username' => <user_name>,
'password' => <user_pwd>
));
This wasn't documented anywhere and figured it out through trial and error.