Add Pdo-mysql driver for PHP, PHP add pdo-mysql_php Tutorial

Source: Internet
Author: User
Tags config php zts yii

Add Pdo-mysql driver for PHP, PHP add pdo-mysql


First, the question

The company has an old Linux server, apache+mysql+php structure, to a recent PHP project to deploy to the above, as a test environment,

Since the new project was developed using the PHP yii framework, and the data access of the YII framework uses the PDO interface, Pdo_mysql driver support is required.

Note: At present, PDO has become the main way for PHP to access the database, which is also the design idea of interface-oriented programming.
The PHP high version also includes PDO, Pdo-sqlite, and pdo-mysql support. It is believed that PDO is now supported on most PHP servers.
If you are still using the old MySQL mysqli way, do not use PDO. 】

Second, the idea

There are two ways to configure Pdo-mysql drivers for PHP,
One is to recompile, install, configure PHP, in the Configure when the--with-pdo-mysql parameters can be added,
The other is to add a pdo-mysql extension to the existing PHP base.

Based on the principle of convenience and speed, we have chosen to increase the Pdo-mysql driver on the existing basis.

Third, the specific operation

0. Preparation
The first thing to know is where your current PHP is installed, assuming that you are in/user/local/php
The directory structure is roughly the same,
Bin
etc
Include
Lib
Logs
Mans

To find these files, the following will be used:
Lib/php.ini PHP configuration file, presumably you will not be unfamiliar, it may also be in the ETC directory, to see your specific situation
Bin/phpize This is to add a new extension to PHP without re-editing PHP
Bin/php-config Php-config is a script file that is used to get some information about PHP, such as which directory the PHP is installed in, what the extension library path is, and so on. If you have more than one PHP version installed on your system, this parameter is useful to specify which PHP version your extension is installed on.

Also, be aware of where your MySQL is installed,
This is assumed to be located in/usr/local/mysql


1, download the source code of Pdo-mysql Drive
Web site in Http://pecl.php.net/package/PDO_MYSQL, from the official website can see this way has not been encouraged to use,
Since PDO is already integrated into the PHP kernel, just add a parameter when compiling.

The following steps operate sequentially:

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 point, the Pdo-mysql driver has been compiled and completed,
It's usually in this directory.
/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626
This is where the PHP extension is stored, and there may have been many other extensions, such as memcache.so
Look at the directory and you should already see the pdo_mysql.so library file.


2. Configuring the php.ini File

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

Find extentions This configuration section, and then add pdo_mysql.so on the line


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, even if the completion of the
Apache/bin/apachectl restart

4, phpinfo to see if the effective
Write a PHP file, a simple sentence phpinfo ()

Open http://www.aaa.com/test.php
Search PDO
You will see the following hint that PDO already supports MySQL driver and can operate MySQL database in PHP via PDO.
PDO driverssqlite, Sqlite2, MySQL

http://www.bkjia.com/PHPjc/939719.html www.bkjia.com true http://www.bkjia.com/PHPjc/939719.html techarticle add pdo-mysql driver for PHP, PHP add pdo-mysql One, the problem company has an old Linux server, apache+mysql+php structure, to the recently done a PHP project deployed to the above, do ...

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