search
HomeBackend DevelopmentPHP TutorialDetailed steps for cross-platform migration of application systems based on DB2 and PHP (1)_PHP Tutorial

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

Jul 13, 2016 pm 05:36 PM
db2pphponemainintroducebased onhowFinishoperating systemstepofdetailedCross-platformmigrate

本文主要介绍如何完成基于 DB2 的 PHP 应用系统从 AIX 平台到 Linux 平台的移植过程。文中包含了底层的 DB2 数据库移植、上层的 PHP 应用系统移植的详细步骤以及移植过程中可能遇到的问题和解决方法。

任务概述

系统迁移的工作主要分为以下几个方面:

1.DB2 数据库系统的跨平台迁移

2.Apache 服务器与 php 应用系统的安装和配置

下面我们就分 2 个方面分别介绍迁移和配置的具体步骤。

DB2 数据库系统的跨平台迁移

数据库环境

源环境:AIX+DB2 v8.1

目标环境:Linux+DB2 v8.1

其中源数据库中包含了 2 个数据库 Instance:SRCDB1 与 SRCDB2。在 SRCDB1/SRCDB2 数据库中,均包含了上百张数据库表,并有很多的索引、外键约束、触发器、存储过程以及一些含有自增字段的表(含有 GENERATED ALWAYS AS IDENTITY 定义字段的表)。更为困难的是,我们并没有关于这些数据库对象的准确创建脚本。

迁移方案的选择

如果迁移的源系统与目的系统属于同一类型操作系统,例如 Linux 之间的迁移,或者 AIX 系统之间的迁移,则情况相对简单,DB2 本身已经提供相关的实用工具来实现这种同类型平台之间的数据库移植,如: BACKUP 和 RESTORE 命令。当然,根据不同的情况还需要对实用工具所提供的参数有比较清楚的了解,譬如源系统与目标系统使用不同的表空间,就会涉及到表空间重定向的问题。由于本文的重点在于跨平台的移植,这种方案显然无法满足需求,在此不再熬述。

那么,如何处理跨平台的数据库迁移问题?是不是可以使用实用工具 db2move 呢? db2move 只能迁移表中的数据,而无法对索引、外键约束、触发器和存储过程等数据库对象也实现迁移操作,而且对于包含自增字段数据的表来说,db2move 也有一定的限制。并且 db2move 只能把数据导入到已存在的数据库的表中,无法显示指定表空间的位置。由于在数据库的系统迁移过程中,不仅需要迁移表中的数据,还有索引、外键约束、触发器和存储过程等数据库对象,与本文所选方案相比,还是后者更具优势。可以将 db2move 仅作为迁移表数据的一种备用方案。

而对于 export 和 import 来说,一次只能针对一张表进行导出导入操作,并且需要手动输入 export 和 import 的命令以及需要导入导出的数据表名,在数据库表的数量不多的情况下,这种方案也许还可以考虑,但也不并是最佳的方案。而在数据库中表数量众多的情况下,这种做法则是基本不现实的,而且 import 命令并不能保证自增字段的数据与原来的表数据保持一致。

本文根据 DB2 对数据库对象的处理机制,采用将 db2look 与 DDL、DML 脚本相结合的方式,并针对原数据库中的触发器、存储过程以及外键约束等分别处理,给出了一种跨平台 DB2 数据库系统移植的可行方案。

下面我们以 SRCDB1 为例介绍一下这种情况下的数据库整体迁移过程。SRCDB1 数据库中有 SRCDB1、ASN、DB2DBG 和 SQLDBA 这四个数据库模式。假设 SRCDB1 数据库的用户名为 user_srcdb1,密码:pw_srcdb1。

在源系统 (AIX) 上的相关操作

1.使用 db2look 命令抽取生成数据库对象的 DDL 脚本

清单 1. db2look 命令及参数

# db2look -d SRCDB1 -e -o srcdb1.ddl -a -i user_srcdb1 -w pw_srcdb1

db2look :生成 DDL 以便重新创建在数据库中定义的对象

语法: db2look -d DBname [-e] [-u Creator] [-z Schema]

[-t Tname1 Tname2...TnameN] [-tw Tname] [-h] [-o Fname] [-a]

[-m] [-c] [-r] [-l] [-x] [-xd] [-f] [-fd] [-td x]

[-noview] [-i userID] [-w password]

[-v Vname1 Vname2 ... VnameN] [-wrapper WrapperName]

[-server ServerName] [-nofed]

-d : 数据库名称,必选参数

-e : 抽取复制数据库所需要的 DDL 文件,此选项将生成包含 DDL 语句的脚本

-o : 将输出重定向到给定的文件名,如果未指定 -o 选项,则输出默认转到 stdout

-a : 为所有创建程序生成统计信息,如果指定了此选项,则将忽略 -u 选项

-i : 指定登录到数据库所在服务器时所使用的用户标识

-w : 指定登录到数据库所在服务器时所使用的密码

2.根据不同类型对象,分化数据库对象 DDL 脚本

Since each table data in the source database has been processed by database objects such as triggers and stored procedures, in order to ensure the consistency and integrity of the data in the database, these database objects should be created after importing the data. To prevent repeated execution of database objects such as triggers and stored procedures to generate erroneous data when importing table data. Use a text editor to edit srcdb1.ddl generated by db2look, divide the DDL statements that create tables and indexes, create foreign key constraints, and create triggers and stored procedures into four groups, and save them as the following four DDL script:


srcdb1_tables.ddl srcdb1_foriegnkeys.ddl

srcdb1_triggers.ddl srcdb1_procedures.ddl

srcdb1_tables.ddl: Contains ddl statements to create SEQUENCE, UDF, TABLE, VIEW and other database objects.

Listing 2. srcdb1_tables.ddl statement

CREATE SEQUENCE "SRCDB1"."SAMPLE_SEQ_1" AS INTEGER

MINVALUE 1 MAXVALUE 9999999999

START WITH 1 INCREMENT BY 1;

CREATE FUNCTION " SRCDB1"." SAMPLE _FUNC_1" (

VARCHAR(254),

VARCHAR(254),

VARCHAR(254)

) RETURNS VARCHAR(254)

SPECIFIC SAMPLE _FUNC_1 ……;

CREATE TABLE " SRCDB1"." SAMPLE _TAB_1" (

"TAB_COL1" CHAR(20) NOT NULL ,

"TAB_COL2" VARCHAR(70) NOT NULL ) ;

CREATE TABLE " SRCDB1"." SAMPLE _TAB_2" (…);

……

CREATE TABLE " SRCDB1"." SAMPLE _TAB_N" (…);

CREATE VIEW SRCDB1.SAMPLE_VIEW_1 (VIEW_COL1,VIEW_COL2) AS SELECT distinct

COL1 , COL2 FROM SAMPLE_TAB WHERE ……;

CREATE VIEW SRCDB1.SAMPLE_VIEW_2 ……;

……

CREATE VIEW SRCDB1.SAMPLE_VIEW_N ……;

srcdb1_foriegnkeys.ddl: Contains ddl statements to create foreign key constraints.

Listing 3. srcdb1_foriegnkeys.ddl statement

ALTER TABLE " SRCDB1"."SAMPLE_FK_1"

ADD CONSTRAINT "SQL030903143850120" FOREIGN KEY

("FK_COL1")

REFERENCES " SRCDB1"."SAMPLE_TABLE"

("COL1");

ALTER TABLE " SRCDB1"."SAMPLE_FK_2" ADD ……;

……

ALTER TABLE " SRCDB1"."SAMPLE_FK_N" ADD ……;

srcdb1_triggers.ddl: Contains ddl statements to create triggers.

Listing 4. srcdb1_triggers.ddl statement

CREATE TRIGGER SRCDB1.SAMPLE_TRIG_1 AFTER UPDATE OF col1 ON SRCDB1.SAMPLE_TAB


REFERENCING NEW AS n FOR EACH ROW MODE DB2SQL WHEN ( n.col1 > 3)

BEGIN ATOMIC

update SAMPLE_TAB

set(col2) = anotherValue where col1 = n.col1 ;--

END;

CREATE TRIGGER SRCDB1. SAMPLE_TRIG_2 ……;

……

CREATE TRIGGER SRCDB1. SAMPLE_TRIG_N ……;

srcdb1_procedures.ddl: Contains ddl statements to create SQL stored procedures and java stored procedures.

Listing 5. srcdb1_procedures.ddl statement

CREATE PROCEDURE " SRCDB1"." JAVA_PROCEDURE_1" (

OUT SQLSTATE CHARACTER(5),

OUT ROWS_SUBMITED INTEGER,

IN BATCH_ID INTEGER,

IN LEVEL VARCHAR(4000)

)

DYNAMIC RESULT SETS 0

SPECIFIC SUBMIT_BATCH

EXTERNAL NAME Submit_batch!submit_batch

LANGUAGE JAVA

PARAMETER STYLE JAVA

NOT DETERMINISTIC

FENCED THREADSAFE

MODIFIES SQL DATA

NO DBINFO;

CREATE PROCEDURE " SRCDB1"."JAVA_PROCEDURE_2" ……;

……

CREATE PROCEDURE " SRCDB1"."JAVA_PROCEDURE_N" ……;


SET CURRENT SCHEMA = " SRCDB1";

SET CURRENT PATH = "SYSIBM","SYSFUN"," SRCDB1";

CREATE PROCEDURE SRCDB1.SQL_PROCEDURE_1 (

IN hostname varchar(4000),

IN username varchar(4000),

OUT SQLCODE_OUT int )

SPECIFIC SRCDB1.SQL_PROCEDURE_1

LANGUAGE SQL

-------------------------------------------------- --

-- SQL Stored Procedure

-------------------------------------------------- --

P1: BEGIN

……

END P1 ;

CREATE PROCEDURE SRCDB1.SQL_PROCEDURE_2 ……;

……

CREATE PROCEDURE SRCDB1.SQL_PROCEDURE_N…;

It should be noted that the db2 v6 version of db2look has not yet implemented the ddl statement for extracting database objects such as UDF, TRIGGER, UserSpace, NodeGroup, BufferPool, etc. Starting from db2 v7, db2look can extract the DDL of the above objects, but it still cannot extract the ddl statement that creates the stored procedure object. Starting from db2 v8.2, support for the db2look function has been improved, and the extraction function of stored procedure ddl statements has been implemented. Since the source database system involved in this article is of a lower version (DB2 v8.1), the above solution needs to be adopted to obtain the DDL information of all database objects:

1). Perform a CATALOG operation on SRCDB1 (DB2 v8.1 version) from a DB2 v8.2 system:


db2 catalog db SRCDB1 as SRCDB1;

2). db2look extraction process of SRCDB1 from DB2 v8.2 system:

db2look -d SRCDB1 -e -o srcdb1.ddl -a -i user_srcdb1 -w pw_srcdb1;

This way you can get the complete database object DDL information.

3. Generate data export expo

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/508263.htmlTechArticleThis article mainly introduces how to complete the transplantation process of PHP application system based on DB2 from AIX platform to Linux platform. The article includes the underlying DB2 database transplantation and the upper-level PHP application system...

Statement
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
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)