Two Methods for PDO_MYSQL extension installation in PHP

Source: Internet
Author: User

Two Methods for PDO_MYSQL extension installation in PHP

Method 1

The CakePHP document requires the installation of the pdo_mysql extension, so I tried to install it.

Here, my system is CentOS 6.0. If your system is of another version of Linux/Unix, refer. If your system is Windows, sorry, the following content is not suitable for you, please move.

First, download the pdo_mysql extension source code package. Download the page at http://pecl.php.net/package/pdo_mysql. You can download the file and then upload it to the server using FTP.

I used wget to directly download it to the server after copying it.

# Wget http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz

Then decompress the package.

# Tar-zxvf PDO_MYSQL-1.0.2.tgz

Enter the decompressed directory and run phpize.

#/Usr/local/php/bin/phpize

Processing ing:

PHP Api Version: 20100412

Zend Module Api No: 20100525

Zend Extension Api No: 220100525

Generate makefile. The following two parameters must be added. I didn't add them at first, and the results both indicated that the header files of php-config and mysql could not be found.

#./Configure-with-php-config =/usr/local/php/bin/php-config-with-pdo-mysql =/usr/local/mysql

A soft connection to the mysql header file is also required before make. Because the directory is specified during mysql installation and the header file cannot be found without soft connection.

# Ln-s/usr/local/mysql/include/*/usr/local/include/

Then make and make install.

# Make

# Make install

The following message is displayed, indicating that the extension is installed in the following directory.

Installing shared extensions:/usr/local/php/lib/php/extensions/no-debug-zts-20100525/

For convenience, I moved the pdo_mysql.so file to the extensions directory.

# Mv/usr/local/php/lib/php/extensions/no-debug-zts-20100525/pdo_mysql.so/usr/local/php/lib/php/extensions/

Then you can modify the php. ini file.

Find the line; extension_dir = "./", remove the comment, and modify the path.

Extension_dir = "/usr/local/php/lib/php/extensions /"

After my tests, I found that php only looks for extensions of so from this directory, rather than subdirectories under this directory. So I previously moved all the so files to this directory for unified management.

Find the line; extension = php_pdo_mysql.dll, remove the comment, and modify the file name.

Extension = pdo_mysql.so

The file name is not the same. here we need to remove the php _ prefix; otherwise, the file cannot be found. The dll is the file name in windows. We changed it to so.

Restart apache. You can use phpinfo () to check whether it has taken effect.

Method 2

The following operations of PDO_MYSQL are performed in Linux.

1. download the file or enter ext/pdo_mysql in the PHP source package

Http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz

2. decompress the file

Tar zxvf PDO_MYSQL-1.0.2.tgz

3. Configure and compile files

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

Note: My PHP is installed in:/usr/local/php/mysql. When installing:/usr/local/mysql, pay attention to where your own installation directory is.

3. install it in PHP configuration

Remember this and open the php. ini file,

Add a row

Extension = pdo_mysql.so

Windows pdo mysql extension Installation

Php. ini does not enable pdo. Therefore, modify php. ini and remove the semicolon before the code shown below. The modified code is as follows:

Extension_dir = "E:/amp/php/ext" // configure your own ext directory path here

......

Extension = php_mysql.dll

......

Extension = php_pdo.dll

......

Extension = php_pdo_mysql.dll

After you restart apache, the following error is returned:

CDbConnection cannot enable the database connection: cocould not find driver

It means that the database driver cannot be found. I used phpinfo to check that PDO is enabled, but the no value is displayed in the database supported by PDO, indicating that the extension php_pdo_mysql.dll cannot be loaded. After many attempts, including changing the php version and mysql version. But none of them work. Is it true that the mysql pdo extension of php cannot be enabled?

I checked it online and found a solution.

Method 1: add the PATH of the php installation directory to the PATH of the system environment variable to solve the problem.

Method 2: Because I deployed a running server on the server, it cannot be restarted. Therefore, you can copy libmysql. dll under the php installation directory to the windows directory.

Restart apache

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.