Home > Backend Development > PHP Tutorial > Detailed steps for cross-platform migration of application systems based on DB2 and PHP (2)_PHP Tutorial

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

WBOY
Release: 2016-07-13 17:35:51
Original
1036 people have browsed it

5.处理数据库表中的自增字段

对于需要加载的含有自增字段的表,即该表的 ixf 数据文件中有自增列的值, 可以在 load 命令中加入如下参数控制自增字段值:
1). modified by identityignore :加载的数据文件中有自增字段值,load 时忽略数据文件中自增字段值 ;


2). modified by identitymissing :加载的数据文件中没有自增字段值,load 时自动生成自增字段值 ;

3). modified by identityoverride :加载的数据文件中有自增字段值,load 时使用数据文件中的自增字段值 。

为了使目标数据库中含有自增字段的表中数据与源数据库中的数据保持一致,本文实例中选择使用 modified by identityoverride 参数,在导入数据时使用数据文件中的自增字段值。读者可以根据不同情况选择适当的控制参数。

首先,在 srcdb1_tables.ddl 文件中查找所有包自增字段的表名 ( 含有 GENERATED ALWAYS AS IDENTITY 字段的表 ),然后在 srcdb1_load.sql 中将 modified by identityoverride 语句片段插入到这些含有自增字段的表所对应的 load 命令行中。

清单8. load 脚本中自增字段处理

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

6.执行导出脚本

执行导出脚本,导出所有表的数据 。

# db2 -tvf srcdb1_export.sql

导出的表数据以 ixf 格式存放于当前路径下。

7.保存脚本和数据文件

将所有 DDL 脚本以及数据文件 *.ixf 复制到目标系统所在站点。

LINUX 系统上的操作

1.通过命令行处理器(CLP)创建实例 SRCDB1:

# db2icrt SRCDB1

2.使用 CREATE DATABASE 命令创建数据库 SRCDB1,创建必要的表空间及配置必要的数据库参数。

# db2 create database SRCDB1

3.连接到数据库 SRCDB1,执行 srcdb1_tables.ddl 脚本创建缓冲池,表空间,UDF,表以及 Index,Sequence,视图等数据库对象。

# db2 connect to srcdb1

# db2 -tvf srcdb1_tables.ddl

4.进入到放置 .ixf 数据文件的目录,执行下面的命令导入表数据。

# db2 -tvf srcdb1_load.sql

5.使用 srcdb1_foriegnkeys.ddl,srcdb1_triggers.ddl ,srcdb1_procedures.ddl 脚本文件创建外键约束,触发器和存储过程。

# db2 -tvf srcdb1_foriegnkeys.ddl

# db2 -tvf srcdb1_triggers.ddl

# db2 -tvf srcdb1_procedures.ddl

成功完成上述步骤后,数据库的迁移工作基本完成。

Apache 服务器与 php 的安装和配置

Apache 服务器的安装和配置

Apache HTTP 服务器是一个模块化的软件,管理员可以通过选择服务器中包含的模块进行功能增减。模块可以在编译时被静态包含进httpd二进制文件,也可以编译成独立于httpd二进制文件的动态共享对象 (DSO)。DSO 模块可以与服务器一起编译,也可以用 Apache 扩展工具 (apxs) 单独编译。动态加载的方式相比静态加载具有更高的灵活性。使用动态载入特性,Apache 服务器必须以动态共享对象(DSO,Dynamic Shared Object)的方式编译。Apache 对 DSO 的支持,是基于一个叫 mod_so 的模块来实现的,为支持动态加载方式,这个模块必须预先被静态编译到内核中。因此可以通过 mod_so 模块检测已安装的 Apache 是否支持 DSO:

清单9. mod_so 模块检测

# $APACHEHOME/bin/httpd –l


Compiled in modules:

core.c

prefork.c

http_core.c

mod_so.c

如果在列出的模块名中有 mod_so.c,则说明安装的 Apache 已经支持 DSO,否则需要重新编译 Apache。Apache 的安装和配置过程十分简单,如下所示:

1.下载 httpd-2.0.54.tar.gz(http://httpd.apache.org/),并将其解压到制定目录

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

2.编译安装 apache

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

-- prefix 指定 apache 的安装路径

--enable-module=so 将 so 模块(mod_so)静态编译进 apache 服务器的内核,以支持 DSO 模式

# make && make install

3. 启动 apache

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

# apachectl start

php 的安装和配置

在 php 的安装和配置过程中,有两个方面需要注意,首先是 php 与 apache http server 的结合,其次是 php 与 db2 数据源的连接。

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, this will also bring about some decrease in operating efficiency. The Apache server will be about 20% slower when starting.

PHP also has three ways 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 license. 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 that can compile the php module into a DSO file without apache source code)

--with-ibm-db2 specifies unified ODBC driver as the access interface between php and data sources, and specifies the DB2 instance installation directory.

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

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

Copy 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 main directory of html files: the main directory used to store the web files required for the website

DocumentRoot "/home/web/www/"

Set the order of apache's default file names: apache will search for the default homepage files it supports in the current path in order from front to back

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

Add php interpreted file suffix: For all file types that need to be interpreted by PHP, the suffix needs to be added to the AddType configuration item

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

Load PHP module: load the library libphp4.so under the module directory modules, and add the module structure name php4_module to the active 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, when starting the Apache service, the DB2 client instance environment needs to be initialized 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 the 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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/508262.htmlTechArticle5. 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...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template