Cross-platform migration of application systems based on DB2 and PHP detailed steps (ii) _php tutorial

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

5. Working with the self-increment fields in a database table

For a table with a self-increment field that needs to be loaded, that is, the table's IXF data file has an auto-increment value, you can control the self-increment field value in the load command by adding the following parameters:
1). Modified by Identityignore: The value of the self-increment field is in the loaded data file, and the value of the self-increment field in the data file is ignored in load;


2). Modified by identitymissing: There is no self-increment field value in the loaded data file, and the self-increment field value is automatically generated when load.

3). Modified by Identityoverride: There is a self-increment field value in the loaded data file, and the self-increment field value in the data file is used when load.

In order to keep the data in the table with the self-increment field in the target database consistent with the data in the source database, the modified by Identityoverride parameter is selected in this article to use the self-increment field value from the data file when importing data. The reader can choose the appropriate control parameters according to different situations.

First, look in the Srcdb1_tables.ddl file for the table name of all the package self-increment fields (the table that contains the GENERATED always as IDENTITY field), and then modified by IdentIT in Srcdb1_load.sql The Yoverride statement fragment is inserted into the load command line for those tables that contain the self-increment fields.

Listing 8. Self-increment field handling in load script

DB2 load from TEST.IXF of IXF modified by identityoverride insert into test;

6. Execute Export Script

Executes an export script that exports data for all tables.

# DB2-TVF Srcdb1_export.sql

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

7. Saving scripts and data files

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

Operations on a LINUX system

1. To create an instance from the command line processor (CLP) SRCDB1:

# DB2ICRT SRCDB1

2. Use the CREATE DATABASE command to build the SRCDB1, create the necessary tablespace, and configure the necessary database parameters.

# DB2 CREATE DATABASE SRCDB1

3. Connect to Database SRCDB1, execute SRCDB1_TABLES.DDL scripts to create database objects such as buffer pools, tablespaces, UDFs, tables, and index,sequence, views, and so on.

# 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 the table data.

# DB2-TVF Srcdb1_load.sql

5. Using SRCDB1_FORIEGNKEYS.DDL,SRCDB1_TRIGGERS.DDL, the Srcdb1_procedures.ddl script file creates foreign KEY constraints, triggers, and stored procedures.

# DB2-TVF SRCDB1_FORIEGNKEYS.DDL

# DB2-TVF SRCDB1_TRIGGERS.DDL

# DB2-TVF SRCDB1_PROCEDURES.DDL

After successful completion of the above steps, the migration of the database is basically complete.

Installation and configuration of Apache server with PHP

Installation and configuration of Apache server

Apache HTTP Server is a modular software that allows administrators to add or decrease functionality by selecting the modules included in the server. The module can be statically included in the httpd binary at compile time, or it can be compiled into a dynamic shared object (DSO) independent of the httpd binary file. The DSO module can be compiled with the server, or it can be compiled separately with the Apache extension tool (APXS). Dynamic loading has a higher level of flexibility than static loading. Using the dynamic load feature, the Apache server must be compiled in a dynamically shared object (Dso,dynamic shared object). Apache support for DSO is based on a module called Mod_so, in order to support dynamic loading mode, this module must be statically compiled into the kernel in advance. It is therefore possible to detect if the installed Apache supports DSO with the Mod_so module:

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 name of the module listed, the installation of Apache already supports DSO, otherwise it will need to recompile Apache. The installation and configuration process for Apache is straightforward, as follows:

1. Download httpd-2.0.54.tar.gz (http://httpd.apache.org/) and unzip it to the development 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 for Apache

--enable-module=so the so module (MOD_SO) is statically compiled into the Apache server's kernel to support DSO mode

# Make && make install

3. Launch Apache

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

# Apachectl Start

Installation and configuration of PHP

In the process of installing and configuring PHP, there are two aspects to be aware of, first, PHP and Apache HTTP server, followed by PHP and DB2 data source connection.

When installing PHP in the Apache environment, there are three installation modes to choose from: Static modules, dynamic modules (DSO), and CGI. It is recommended to install in DSO mode, which is relatively simple to maintain and upgrade, and can dynamically add new function modules according to demand without recompiling Apache. Of course, this will also lead to some operational inefficiencies, and the Apache server will slow down about 20% when it starts.

There are also three ways to connect DB2 data sources in PHP: Unified ODBC Driver, IBM_DB2, and PDO (PHP data Object).

Unified ODBC Driver is one of the oldest extension modules for PHP access to databases. Starting with DB2 v7.2, unified ODBC driver supports access to it. For all ODBC-enabled databases, the unified ODBC driver provides a unified data access interface. To ensure the generality of the interface, unified ODBC driver does not make specific optimizations for different types of databases.

IBM_DB2 is an extension module developed and maintained by IBM that interacts with the DB2 data source, which adheres to the open source protocol. For applications based on DB2 UDB and PHP 4.x, IBM_DB2 is the optimal choice because it is optimized for DB2 UDB and avoids some compatibility issues that may exist when using unified ODBC driver. However, IBM_DB2 only supports DB2 v8.2.2 or later.

PDO is the new database access method that will be supported in PHP 5.x. In this article, because the source database and the target database version are DB2 v8.1, and the source environment in the unified ODBC driver, in order to maintain the consistency of the environment configuration, still choose unified ODBC Driver as PHP and data source access interface.

The installation and configuration process for 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 the PHP source code to compile

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

--prefix specifying the installation path for PHP

--WITH-APXS2 specifies the path to the APXS program (APXS is a Perl script that compiles the PHP module into the DSO file from the Apache source code)

--WITH-IBM-DB2 Specifies the unified ODBC driver as the provider of PHP to the data source and specifies the instance installation directory for DB2.

--without-mysql Ignore default installation configuration for MySQL database

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

Copy the php.ini-dist from 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 to make the following changes:

Set HTML file home directory: The home directory for the Web files required for the Web site

DocumentRoot "/home/web/www/"

Set the order of the default file names for Apache: Apache will find the default home files that it supports in the current path in the order before and after

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

Add php explanation file suffix: For all file types that need to be interpreted by PHP, you need to add suffixes to the AddType configuration item

AddType application/x-httpd-php. Php. Inc

Load PHP module: Load the library libphp4.so under Module directory modules and add the module structure name php4_module to the list of active modules

LoadModule Php4_module modules/libphp4.so

4. To edit a configuration file/usr/local/apache2/bin/apachectl:

To ensure connectivity to the DB2 database, the DB2 client instance environment needs to be initialized at the same time when the Apache service is started. When you create an DB2 instance, DB2 automatically generates 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, which reads as follows:

Echo Phpinfo ();
?>

It is stored in the Apache HTML file home directory/home/web/www, through the browser to access the Web page, if the normal access (as shown), the configuration work is complete.


Conclusion

This paper mainly covers a cross-platform porting process based on PHP and DB2 UDB application system, and introduces the cross-platform migration of DB2 database system and the installation and configuration process of Apache Server and PHP application system. Based on practical experience, it provides a feasible solution for cross-platform migration of DB2 database system. This article also gives a detailed description of the problems that may arise during the migration process, and provides a corresponding solution. While this article deals with the porting of applications from AIX systems to LINUX systems, readers can also refer to specific porting processes and apply them to other platforms.

http://www.bkjia.com/PHPjc/508262.html www.bkjia.com true http://www.bkjia.com/PHPjc/508262.html techarticle 5. Working with the self-increment field in a database table for the table containing the self-increment fields that need to be loaded, that is, the table's IXF data file has the values of the self-increment, you can add the following parameters to the load command ...

  • 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.