Zend_Db connect to DB2

General discussion on Zend Server for IBM System i
marcoart
Posts: 25
Joined: Thu Feb 17, 2011 12:09 pm
Location: Roma
Contact:

Zend_Db connect to DB2

Post by marcoart » Sat Apr 02, 2011 12:27 pm

Hi guys,

I'm trying to connect to db2 with Zend_Db but i want to do in runtime.

i set into Bootstrap class this code

Code: Select all

function _initRegDataBase(){
		$this->bootstrap('db');
		$ResourceDb = $this->getResource('db');
		$ResourceDb->setFetchMode(Zend_Db::FETCH_OBJ);
}
into application.in these parametres:
resources.db.adapter = "DB2"
resources.db.params.host = "xxx.xxx.x.xxx"
resources.db.params.username = ""
resources.db.params.password = ""
resources.db.params.dbname = "xxxxx"
resources.db.params.driver_options.i5_lib = "LIBRARY"
resources.db.params.adapterNamespace = "Zend_Db_Adapter"
resources.db.params.os = "i5"

and when I launch an action from the controller i need to connect to db2 with user and pwd that i take from form login:

Code: Select all

$params = array('host'=>'xxx.xxx.x.xxx', 'dbname'=>'xxxxx', 'driver_options.i5_lib'=>'LIBRARY, 'adapterNamespace'=>'Zend_Db_Adapter', 'os'=>'i5', 'username'=>$user, 'password'=>$pwd, 'port'=>'50000', 'protocol'=>'TCPIP');

$ResourceDb = Zend_Db::factory('pdo_ibm',$params);

$ResourceDb->setFetchMode(Zend_Db::FETCH_OBJ);
Zend_Db_Table_Abstract::setDefaultAdapter($ResourceDb);
i receive this error:
SQLSTATE=42705, SQLConnect: -95 The relational database is not relational database into address

how can i solve it? wich other parametres i have to set into $params?

thanks
Best Regards
______________________________________________
Ristoranti Roma

e-mail: info@ristorantiromaristo.it
http://www.ristorantiromaristo.it

aseiden
Posts: 875
Joined: Thu Apr 09, 2009 5:45 pm

Re: Zend_Db connect to DB2

Post by aseiden » Sun Apr 03, 2011 6:47 pm

Hi,

You are close, but I see at least one problem:

Code: Select all

$ResourceDb = Zend_Db::factory('pdo_ibm',$params);
The better adapter to use is "Db2".

Code: Select all

$ResourceDb = Zend_Db::factory('Db2',$params);
I recently did a webinar with Zend on this topic (Zend_Db with DB2 on IBM i, library lists, etc.). To view it, go to http://www.zend.com/en/resources/webinars/i5-os and look for "From Zero to ZF: Your first Zend Framework project on IBM i."

Let us know how it goes.

Best,
Alan

marcoart
Posts: 25
Joined: Thu Feb 17, 2011 12:09 pm
Location: Roma
Contact:

Re: Zend_Db connect to DB2

Post by marcoart » Mon Apr 04, 2011 8:38 am

hi!
thanks for your answer!

I try with "Db2" adapter and i receive this error: SQLCODE=-204 (file not found in library QTMHHTTP).

so i set the library file into 'driver_options.i5_lib'=>'LIBxxxx',
but is there specifi parametres to set? to find this file?

thanks
Best Regards
______________________________________________
Ristoranti Roma

e-mail: info@ristorantiromaristo.it
http://www.ristorantiromaristo.it

erich_hieden
Posts: 393
Joined: Tue Jul 07, 2009 9:01 am

Re: Zend_Db connect to DB2

Post by erich_hieden » Mon Apr 04, 2011 2:35 pm

You can set the library in your SQL-Query. i.e.

Code: Select all

select * from LIBRARY.table

marcoart
Posts: 25
Joined: Thu Feb 17, 2011 12:09 pm
Location: Roma
Contact:

Re: Zend_Db connect to DB2

Post by marcoart » Mon Apr 04, 2011 4:13 pm

i not understand why it find file in library QTMHHTTP (that is the USER)

i also pass i5_lib="MYLIBRARY" parametres and username parametres='QTMHHTTP'
Best Regards
______________________________________________
Ristoranti Roma

e-mail: info@ristorantiromaristo.it
http://www.ristorantiromaristo.it

erich_hieden
Posts: 393
Joined: Tue Jul 07, 2009 9:01 am

Re: Zend_Db connect to DB2

Post by erich_hieden » Mon Apr 04, 2011 5:05 pm

Please post the code that is actually causing the problems and at least a few lines above.

Regards

marcoart
Posts: 25
Joined: Thu Feb 17, 2011 12:09 pm
Location: Roma
Contact:

Re: Zend_Db connect to DB2

Post by marcoart » Mon Apr 04, 2011 10:37 pm

this is the code:

Code: Select all

$params = array('host'=>"192.168.x.xxx", 'i5_lib'=>"MYLIBRARY", 'username'=>$user, 'password'=>$pwd, 'dbname'=>"S06C2784", 'adapterNamespace'=>"Zend_Db_Adapter", 'os'=>"i5",'port'=>"50000", 'protocol'=>"TCPIP");	
	
$ResourceDb = Zend_Db::factory('DB2',$params);
$ResourceDb->setFetchMode(Zend_Db::FETCH_OBJ);
Zend_Db_Table_Abstract::setDefaultAdapter($ResourceDb);
now when i try to do fetchRow(); i see that search into differnt library (not into MYLIBRARY but i see that it search into $user) and receive -204 error
Best Regards
______________________________________________
Ristoranti Roma

e-mail: info@ristorantiromaristo.it
http://www.ristorantiromaristo.it

erich_hieden
Posts: 393
Joined: Tue Jul 07, 2009 9:01 am

Re: Zend_Db connect to DB2

Post by erich_hieden » Tue Apr 05, 2011 7:11 am

Somewhere you need to specify a SQL-Statement and I think that the error comes from that part of the code. So please post the code down to AND including fetchRow().

aseiden
Posts: 875
Joined: Thu Apr 09, 2009 5:45 pm

Re: Zend_Db connect to DB2

Post by aseiden » Tue Apr 05, 2011 7:35 pm

Hi, marcoart,

If you want to use library lists, you must turn on i5_naming:

Code: Select all

i5_naming = DB2_I5_NAMING_ON
In addition, if you are using Zend_Db_Table with library lists, you must install a "fix" for the Zend_Db adapter. Please see pages 43-53 of this PowerPoint deck: http://www.slideshare.net/aseiden/your- ... t-on-ibm-i

You can also hear it at http://www.zend.com/en/resources/webinars/i5-os and scroll down to "From Zero to ZF: Your first Zend Framework project on IBM i."

It's not difficult, but you must follow the instructions carefully. This slide deck is the only set of instructions that I know of, with a code fix, to allow Zend_Db_Table to work with library lists. People have told me that it worked for them.

Let us know how it goes.

Best,
Alan

marcoart
Posts: 25
Joined: Thu Feb 17, 2011 12:09 pm
Location: Roma
Contact:

Re: Zend_Db connect to DB2

Post by marcoart » Wed Apr 06, 2011 8:46 am

Hi alan,

thanks for your answer!
can i solve it using $_schema in model confuration?

i try in this way

Code: Select all

class Application_Model_DbTable_TableName extends Zend_Db_Table_Abstract
{
    protected $_name = 'TABLE_NAME';
    protected $_schema = 'LIBRARY';
    protected $_primary = 'KEYNAME';
}
and than:

Code: Select all

        $list = new Application_Model_DbTable_TableName;
        $this->view->list = $list->fetchAll();
but i receive this error:
SQLCODE=-5001

how not work also with $_schema? is the same problems?
thanks
Best Regards
______________________________________________
Ristoranti Roma

e-mail: info@ristorantiromaristo.it
http://www.ristorantiromaristo.it

Post Reply