database. The background for this approach is that compared to DB2, MySQL
does not have schemas, nor instances.
In MySQL, a table can be referenced by
database.tablename
. If no database
name is provide in the table name, the default is the currently used database. In
DB2, table name is defined as
schema.tablename.
When reference to a DB2
table, if no schema is provided, the default schema is the user ID which is
connected to the database. In an application, the
set schema
statement can be
used to provide a global schema name for the tables which do not have a full
table name specified. To simplify the application conversion, during database
porting the tables were created with the schema of the MySQL database name
(in our case
itsodb
). By using the
set schema
after database connection, we do
not need to change every table name in the application.
Example 7 23 Connecting a DB2 database
$db_user = "itsosj";
$db_pass = "itsosj";
$datab = "itsodb";
$db=odbc_connect($datab,$db_user,$db_pass) or die("Could not connect ".
odbc_errormsg());
$query="SET CURRENT SCHEMA= ITSODB ";
odbc_exec($db,$query) or die(odbc_errormsg($db));
A complement function to the persistent connect function
mysql_pconnect()
is
the
odbc_pconnect().
SELECT query statements
Querying a table in MySQL using the PHP MySQL functions is shown in
Example 7 24.
Example 7 24 MySQL select example
$sql = mysql_query("SELECT * FROM catalog WHERE id= $id ");
$rowsql = mysql_fetch_row($sql);
$graphic = "../graphic/".$rowsql[11].".jpg";
The correspondent ODBC DB2 query is shown in Example 7 25.
Example 7 25 DB2 select example
$sql = odbc_exec($db,"SELECT * FROM catalog WHERE id=$id");
odbc_fetch_into($sql,$rowsql);
$graphic = "../graphics/".$rowsql[11].".jpg";
180
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