5. Processing auto-increment fields in database tables.
For tables containing auto-increment fields that need to be loaded, that is, the ixf data file of the table has auto-increment column values, you can add the following parameters to the load command to control the auto-increment field values:
1). modified by identityignore: There are auto-increment field values in the loaded data file, and the auto-increment field values in the data file are ignored when loading;
2). Modified by identitymissing: There is no auto-increment field value in the loaded data file, and the auto-increment field value is automatically generated when loading;
3). Modified by identityoverride: There is an auto-increment field value in the loaded data file, and the data file is used when loading. The auto-increment field value in .
In order to make the data in the table containing auto-increment fields in the target database consistent with the data in the source database, we choose to use the modified by identityoverride parameter in the example of this article, and use the auto-increment field values in the data file when importing data. Readers can choose appropriate control parameters according to different situations.
First, search the srcdb1_tables.ddl file for all table names that contain auto-increment fields (tables containing GENERATED ALWAYS AS IDENTITY fields), and then insert the modified by identityoverride statement fragment into these tables with auto-increment fields in srcdb1_load.sql. in the corresponding load command line.
Listing 8. Processing of auto-added fields in load script
db2 load from test.ixf of ixf modified by identityoverride insert into TEST;
6. Execute the export script
to export the data of all tables.
# db2 -tvf
The table data exported by srcdb1_export.sql is stored in the current path in ixf format.
7. Saving scripts and data files
Copy all DDL scripts and data files *.ixf to the site where the target system is located.
Operation on LINUX system
1. Create instance SRCDB1 through the command line processor (CLP):
# db2icrt SRCDB1
2. Use the CREATE DATABASE command to create the database SRCDB1, create the necessary table space and configure the necessary database parameters.
# db2 create database SRCDB1
3. Connect to the database SRCDB1 and execute the srcdb1_tables.ddl script to create buffer pools, table spaces, UDFs, tables, and database objects such as Index, Sequence, and views.
# db2 connect to srcdb1
# db2 -tvf srcdb1_tables.ddl
4. Enter the directory where the .ixf data file is placed and execute the following command to import table data.
# db2 -tvf srcdb1_load.sql
5. Use the srcdb1_foriegnkeys.ddl, srcdb1_triggers.ddl, srcdb1_procedures.ddl script files 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 successfully completing the above steps, the database migration work is basically completed.
Installation and configuration of Apache server and php
Installation and configuration of Apache server
Apache HTTP server is a modular software, and administrators can increase or decrease functions by selecting modules included in the server. Modules can be statically included into the httpd binary at compile time, or they can be compiled into dynamic shared objects (DSO) independent of the httpd binary. DSO modules can be compiled together with the server or separately using the Apache extension tools (apxs). Dynamic loading is more flexible than static loading. To use the dynamic loading feature, the Apache server must be compiled as a dynamic shared object (DSO, Dynamic Shared Object). Apache's support for DSO is based on a module called mod_so. In order to support dynamic loading, this module must be statically compiled into the kernel in advance. Therefore, you can use the mod_so module to detect whether the 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 there is mod_so.c in the listed module name, it means that the installed Apache already supports DSO, otherwise Apache needs to be recompiled. The installation and configuration process of Apache is very simple, as follows:
1. Download httpd-2.0.54.tar.gz ( http://httpd.apache.org/ ) and extract it to the specified 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 statically compile the so module (mod_so) 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 process
during the installation and configuration of php , there are two aspects that need to be paid attention to, the first is the combination of php and apache http server, and the second is the connection between php and db2 data source.
When installing PHP in the Apache environment, there are three installation modes to choose from: static module, dynamic module (DSO) and CGI. It is recommended to install in DSO mode. The maintenance and upgrade of this mode are relatively simple. New functional modules can be dynamically added according to needs without recompiling Apache. Of course, doing so will also bring about some decrease in operating efficiency. The Apache server will be about 20% slower when starting.
There are also three ways for PHP to connect to DB2 data sources: unified ODBC driver, IBM_DB2 and PDO (php data object).
◆Unified ODBC driver is one of the earliest extension modules for PHP to access databases. Starting with DB2 v7.2, the unified ODBC driver supports access to it. The unified ODBC driver provides a unified data access interface for all databases that support ODBC. In order to ensure the generality of the interface, the unified ODBC driver does not make specific optimizations for different types of databases.
◆IBM_DB2 is an extension module developed and maintained by IBM to interact with DB2 data sources. It complies with the open source agreement. For applications based on DB2 UDB and PHP 4.x, IBM_DB2 is the best choice because it is optimized for DB2 UDB and avoids some compatibility issues that may exist when using the unified ODBC driver. However, IBM_DB2 only supports DB2 v8.2.2 or higher.
◆PDO is a new database access method that will be supported in PHP 5.x. In this article, since the versions of the source database and the target database are both DB2 v8.1, and the source environment uses the unified ODBC driver, in order to maintain the consistency of the environment configuration, the unified ODBC driver is still selected as the access interface between PHP and the data source. .
The installation and configuration process of PHP is as follows:
1. Download and unzip 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 php source code
# ./configure --prefix=/usr/local/php --with-apxs2=/usr/sbin/apxs --without-mysql --with-ibm-db2=/home/reportdb/sqllib
--prefix specifies the installation path of php
--with-apxs2 specifies the path of the apxs program (apxs is a perl script, which can compile the php module into a DSO file without the source code of apache)
--with-ibm-db2 specifies the unified ODBC driver As the access interface between php and data source, and specify the DB2 instance installation directory.
--without-mysql Ignore 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 document.
# 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 home directory of the html file: the home directory used to store the web files required for the website.
DocumentRoot "/home/web/www/"
sets the default for apache The order of file names: apache will search for the supported default homepage file
DirectoryIndex index.php index.html.var index.cgi index.html
in the current path in order from front to back.Add the php interpretation file suffix: for all needs For file types interpreted by PHP, you need to add the suffix to the AddType configuration item
AddType application/x-httpd-php .php .inc
to load the PHP module: load the library libphp4.so under the module directory modules, and add the module structure name php4_module to
LoadModule php4_module modules/libphp4.so
in the active module list
4. Edit the configuration file /usr/local/apache2/bin/apachectl:
In order to ensure connectivity with the DB2 database, when starting the Apache service, you need to initialize the DB2 client instance environment at the same time. When creating a DB2 instance, DB2 will automatically generate a shell script to initialize the required DB2 instance environment. Just 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. Write a PHP test file test.php with the following content:
echo phpinfo();
?>
Store it in the main directory of apache's html file /home/web/www, and access the webpage through the browser. If it can be accessed normally (as shown in the figure below), the configuration work 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 PHP application system. Based on practical experience, a feasible solution is provided for the cross-platform migration problem of DB2 database system. This article also gives a detailed description and corresponding solutions for problems that may arise during the transplantation process. Although this article only covers the application system transplantation process from AIX system to LINUX system, readers can also refer to the specific transplantation process and apply it to other platforms.