Add PDO-Mysql driver for PHP, add pdo-mysql_PHP tutorial for php

Source: Internet
Author: User
Tags zts
Add the PDO-Mysql driver for PHP and pdo-mysql driver for php. Add the PDO-Mysql driver for PHP, and add pdo-mysql for php. I. The problematic company has an old Linux server with the Apache + MySQL + Php structure, deploy a recently developed PHP project to add the PDO-Mysql driver for PHP, and add pdo-mysql for php.

I. problems

The company has an old Linux server in the Apache + MySQL + Php structure. we need to deploy a recent PHP project on it as a test environment,

Because the new project is developed using the YII Framework of PHP, and the data access of the YII Framework uses the PDO interface, PDO_Mysql driver is required.

[Note: currently, PDO has become the main method for PHP to access the database, which is also the design idea for interface programming.
PHP later versions also have built-in support for PDO, PDO-SQLite, and PDO-Mysql. I believe most PHP servers now support PDO.
If you are still using the old mysql mysqli method, do not use PDO .]

II. ideas

To configure the PDO-Mysql driver for PHP,
One is to recompile, install, and configure PHP, and add the -- with-pdo-mysql parameter to configure,
Add a pdo-mysql extension based on the existing PHP.

Based on the principle of convenience and speed, we chose to add the pdo-mysql driver on the existing basis.

III. specific operations

0. preparation
First, you need to know where your current php installation is, assuming that it is located at/user/local/php
The directory structure is roughly like this,
Bin
Etc
Include
Lib
Logs
Man

Find these files and use them below:
The configuration file of lib/php. ini php must be in the etc directory.
Bin/phpize this adds new extensions for php without re-editing php.
Bin/php-config is a script file used to obtain information about php, such as the directory where php is installed and the path of the extension Library. If more than one php version is installed in your system, this parameter is useful to specify the php version to which your extension is installed.

In addition, you must know where your Mysql is installed,
Here we assume it is in/usr/local/mysql


1. download the source code of the pdo-mysql driver.
Web site in http://pecl.php.net/package/PDO_MYSQL, from the official web page can see that this method has been not encouraged to use,
Because PDO has been integrated into the PHP kernel, you only need to add a parameter during compilation.

Follow these steps:

Wget http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
Tar zxvf PDO_MYSQL-1.0.2.tgz
Cd PDO_MYSQL-1.0.2
/Usr/local/php/bin/phpize
./Configure -- with-php-config =/usr/local/php/bin/php-config -- with-pdo-mysql =/usr/local/mysql
Make
Make install


At this time, the pdo-mysql driver has been compiled,
Usually in this directory
/Usr/local/php/lib/php/extensions/no-debug-non-zts-20090626
Here is the storage location of the php extension, and there may be many other extensions, such as memcache. so.
Check the directory to see the pdo_mysql.so library file.


2. configure the php. ini file

Vi/usr/local/php/lib/php. ini

Find the extentions configuration section and add pdo_mysql.so.


Extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613 /"
Extension = "memcache. so"
Extension = "pdo_mysql.so"

3. restart the apache server.
Apache/bin/apachectl restart

4. check whether phpinfo has taken effect.
Write a php file, a simple sentence phpinfo ()

Open http://www.aaa.com/test.php
Search pdo
The following prompt is displayed, indicating that pdo supports the mysql driver. you can use pdo to operate the mysql database in php.
PDO driverssqlite, sqlite2, mysql

Tip 1: The Problem company has an old Linux server, which is in the Apache + MySQL + Php structure. we need to deploy a recently developed PHP project on it...

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.