Detailed steps for cross-platform migration of application systems based on DB2 and PHP (2)

Source: Internet
Author: User
Tags db2 client db2 connect db2 connect to php database perl script

5. Process Auto-increment fields in database tables

For a table containing auto-increment fields to be loaded, that is, the ixf data file of the table contains the value of auto-increment columns, you can add the following parameters to the load command to control the auto-increment field values:
1). modified by identityignore: The loaded data file contains the auto-increment field value. During load, the auto-increment field value in the data file is ignored;


2). modified by identitymissing: The loaded data file does not contain the auto-increment field value. The auto-increment field value is automatically generated during load;

3). modified by identityoverride: The loaded data file contains the auto-increment field value, and the auto-increment field value in the data file is used for load.

To ensure that the data in the table containing the auto-increment field in the target database is consistent with that in the source database, the modified by identityoverride parameter is selected in this example, use the auto-increment field value in the data file when importing data. You can select appropriate control parameters based on different situations.

First, search for the table names of all the packet auto-increment fields (tables containing the generated always as identity field) in the srcdb1_tables.ddl file ), then, insert the modified by identityoverride statement segment in srcdb1_load. SQL to the load command line corresponding to the tables with auto-increment fields.

Listing 8. Auto-increment field processing in the load script

Db2 load from test. ixf of ixf modified by identityoverride insert into TEST;

6. Execute the export script

Run the export script to export data from all tables.

# Db2-tvf srcdb1_export. SQL

The exported table data is stored in the current path in ixf format.

7. Save scripts and data files

Copy all DDL scripts and data files *. ixf to the site where the target system is located.

Operations on LINUX

1. Create an instance SRCDB1 using the command line processor (CLP:

# Db2icrt SRCDB1

2. Use the create database Command to CREATE the DATABASE SRCDB1, CREATE necessary tablespaces, and configure necessary DATABASE parameters.

# Db2 create database SRCDB1

3. Connect to the database SRCDB1 and execute the srcdb1_tables.ddl script to create database objects such as the buffer pool, tablespace, UDF, table, Index, Sequence, and view.

# Db2 connect to srcdb1

# Db2-tvf srcdb1_tables.ddl

4. Go to the directory where the. ixf data file is stored and run the following command to import the table data.

# Db2-tvf srcdb1_load. SQL

5. Use srcdb+foriegnkeys.ddl, srcdb+triggers.ddl, and srcdb+procedures.ddl to create foreign key constraints, triggers, and stored procedures.

# Db2-tvf srcdb1_foriegnkeys.ddl

# Db2-tvf srcdb1_triggers.ddl

# Db2-tvf srcdb1_procedures.ddl

After the above steps are completed, the database migration is basically completed.

Installation and configuration of Apache server and php

Install and configure the Apache server

The Apache HTTP Server is a modular software. The administrator can add or remove functions by selecting modules contained in the server. The module can be statically included in the httpd binary file during compilation, or compiled into a dynamic shared object (DSO) independent of the httpd binary file ). The DSO module can be compiled together with the server or separately using the Apache extension tool (apxs. Dynamic Loading is more flexible than static loading. To use the Dynamic loading feature, the Apache server must be compiled using a Dynamic Shared Object (DSO, Dynamic Shared Object. Apache's support for DSO is implemented based on a module called mod_so. To support dynamic loading, this module must be statically compiled to the kernel in advance. Therefore, you can use the mod_so module to check whether installed Apache supports DSO:

Listing 9. mod_so module Detection

# $ APACHEHOME/bin/httpd-l


Compiled in modules:

Core. c

Prefork. c

Http_core.c

Mod_so.c

If mod_so.c is listed in the module name, it indicates that the installed Apache already supports DSO. Otherwise, you need to recompile Apache. The installation and configuration process of Apache is very simple, as shown below:

1. Download The httpd-2.0.54.tar.gz (http://httpd.apache.org/) and decompress it to the prepared directory

# Tar zxvf httpd-2.0.54.tar.gz & cd httpd-2.0.54

2. Compile and install apache

#./Configure -- prefix =/usr/local/apache2 -- enable-module = so

-- Prefix specifies the installation path of apache

-- Enable-module = so: The so module (mod_so) is statically compiled into the apache server kernel to support DSO mode.

# Make & make install

3. Start apache

# Ln-s/usr/local/apache2/bin/apachectl/sbin/apachectl

# Apachectl start

Php installation and configuration

During the installation and configuration of php, there are two aspects to note: first, the combination of php and apache http server, and second, the connection between php and db2 data sources.

When installing PHP in Apache, three installation modes are available: static module, dynamic module (DSO), and CGI. We recommend that you install it in DSO mode. maintenance and upgrade in this mode are relatively simple. You can dynamically add new function modules as needed without re-compiling Apache. Of course, this will also bring about a decrease in the running efficiency, and the Apache server will slow down by about 20% at startup.

There are also three ways for PHP to connect to the DB2 data source: uniied ODBC driver, IBM_DB2, and PDO (php data object ).

◆ The uniied ODBC driver is one of the earliest extension modules for PHP database access. Since DB2 v7.2, the unified ODBC driver supports access to it. For all databases that support ODBC, the unified ODBC driver provides a unified data access interface. To ensure the universality of interfaces, the unified ODBC driver does not perform specific optimization on different types of databases.

◆ IBM_DB2 is an extension module developed and maintained by IBM to interact with DB2 data sources. It complies with open source protocols. For applications based on DB2 UDB and php 4.x, IBM_DB2 is the best choice because it is optimized for DB2 UDB, at the same time, it avoids some compatibility problems that may exist when using the unified ODBC driver. However, IBM_DB2 only supports DB2 v8.2.2 or later.

◆ PDO is the new database access method to be supported in php 5.x. In this article, because both the source database and target database versions are DB2 v8.1 and the source environment adopts the unified ODBC driver method, in order to maintain the consistency of Environment configuration, still select the unified ODBC driver as the access interface between php and the data source.

The installation and configuration of PHP are as follows:

1. Download and unzip the php-4.4.4.tar.gz (http://www.php.net /)


# Tar zxvf php-4.4.4.tar.gz

# Cd php-4.4.4

2. Configure and compile the php source code

#./Configure -- prefix =/usr/local/php -- with-apxs2 =/usr/sbin/apxs -- without-mysql -- with-ibm-db2 =/home/reportdb/sqllib

-- Prefix specifies the php installation path

-- The with-apxs2 specifies the path of the apxs Program (apxs is a perl script that can be compiled into a DSO file from the apache source code)

-- The with-ibm-db2 specifies the uniied ODBC driver as the access interface between php and the data source, and specifies the instance installation directory for DB2.

-- Without-mysql ignores the default installation configuration of the mysql database

# Cp php. ini-dist/usr/local/lib

Copy the php. ini-dist in the php installation file to/usr/local/lib as the php configuration file.

# Make & make install

# Cp php. ini-dist/usr/local/lib/php. ini

3. Edit the/usr/local/apache2/conf/httpd. conf file and make the following changes:

Set the html file home directory: the home directory used to store the web files required by the website

DocumentRoot "/home/web/www /"

Set the default file name order of apache: apache will search for the supported default home page files in the current path in the order from top to bottom.

DirectoryIndex index. php index.html. var index. cgi index.html

Add the extension of the php interpretation file: For all file types that need to be interpreted by PHP, add the extension to the AddType configuration item

AddType application/x-httpd-php. php. inc

Load the PHP module: load the library libphp4.so under the Module Directory, and add the module structure name php4_module to the activity module list.

LoadModule php4_module modules/libphp4.so

4. Edit the configuration file/usr/local/apache2/bin/apachectl:

To ensure connectivity with the DB2 database, you must initialize the DB2 client instance environment when starting the Apache service. When you create a DB2 instance, DB2 automatically generates a shell script to initialize the required DB2 instance environment. You only need to call it directly:

If test-f/home/reportdb/sqllib/db2profile; then

./Home/reportdb/sqllib/db2profile

Fi

5. Then, restart the Apache server to inherit the above configuration changes.

# Apachectl restart

6. Compile the PHP test file test. php with the following content:

Echo phpinfo ();
?>

Store it in the apache html file home directory/home/web/www and access the webpage through a browser. If the webpage can be accessed normally (as shown in), the configuration is complete.


Conclusion

This article mainly covers the cross-platform migration process of an application system based on php and DB2 UDB. It details the cross-platform migration of the DB2 database system and the installation and configuration process of the Apache server and the php application system. Based on practical experience, it provides a feasible solution for cross-platform migration of the DB2 database system. This article also gives a detailed description of the problems that may occur during the migration process and provides corresponding solutions. Although this article only involves the porting process from the AIX system to the LINUX system, you can also refer to the specific porting process to apply it to other platforms.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.