// Loads adodb mysql.inc.php for mysql
ADOLoadCode( mysql );
// Loads adodb db2.inc.php for db2
ADOLoadCode( db2 );
Connecting to database
ADOdb uses an object oriented approach to manage the complexity of
handling multiple databases. This is done by passing an input parameter for
the database driver name while creating the connection object. The
connection instance for DB2 can be created using
ADONewConnection( db2 )
or
NewADOConnection( db2 )
.
After creating the connection instance, you need to connect to the database
using:
PConnect()
It creates a persistent connection, which is faster because this connection
is never closed.
Connect()
It creates a non persistent connection, which takes up much fewer
resources though, therefore reducing the risk of your database and your
Web server becoming overloaded.
NConnect()
It forces the creation of a new connection.
Example 7 31 and Example 7 32 show the changes in connection code in the
ADOdb PHP program. All the above connect methods take four parameters
(systemname, username, password, databasename) in MySQL, whereas in
DB2 UDB ODBC, it only requires three parameters (dbname, username,
password). Also, we can set the cursor mode to
SQL_CUR_USE_ODBC
for
optimization purposes
.
Example 7 31 MySQL creating connection in ADOdb
// create connection instance for MySQL
$db = &ADONewConnection( mysql );
$db >Connect( localhost , itso , itso , itsodb );
Example 7 32 DB2 creating connection in ADOdb
// create connection instance for DB2 UDB
$conn = &ADONewConnection( db2 );
$conn >curMode = SQL_CUR_USE_ODBC;
$conn >Connect( itsodb2 , itso , itso );
184
MySQL to DB2 UDB Conversion Guide
footer
Our partners:
PHP: Hypertext Preprocessor Cheap Web Hosting
JSP Web Hosting
Ontario Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Java Hosting
Cheapest Hosting
Visionwebhosting.net Business web hosting division of Vision Web Hosting Inc.. All rights reserved