PDO in PHP

Source: Internet
Author: User
Tags config ini mysql version phpinfo zts zend

Method One

See the cake document required to install the pdo_mysql extension, so try to install it.

Here my system is CentOS 6.0. If your system is another version of the Linux/unix, you can refer to it. If your system is windows, sorry, the following content is not suitable for you, please go.

The first is to download the Pdo_mysql extended source package. Download the page here: Http://pecl.php.net/package/PDO_MYSQL. You can download it and upload it to the server using FTP.

I downloaded it directly to the server side using wget after copying the download address.

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

And then the decompression.

# TAR-ZXVF Pdo_mysql-1.0.2.tgz

Go to the unpacked directory and execute phpize.

#/usr/local/php/bin/phpize

Configuring for:

PHP Api version:20100412

Zend Module Api no:20100525

Zend Extension Api no:220100525

The following generates makefile. The following two parameters must be added, at the beginning I did not add, the results are prompted to find Php-config and MySQL header file.

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

Make a soft connection to the header file of MySQL before making. Because the MySQL installation specified the directory, do not make a soft connection, or can not find the header file.

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

Then make and make install.

# make

# make Install

It will then be prompted as follows, meaning 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/

You can then modify the php.ini file.

Find Extension_dir = "./" This line, remove the annotation, and modify the path.

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

After I tested this, I found that PHP only looks for extensions so from this directory, not subdirectories in that directory. So I moved the so file to the directory for unified Management.

Find Extension=php_pdo_mysql.dll this line, remove the annotation, and modify the file name that follows.

Extension=pdo_mysql.so

File name is not the same, here to remove the PHP_ prefix, or can not find the file. The later DLL is the name of the file under Windows, and we change to so.

Finally reboot the Apache is OK. Use Phpinfo () to see that the discovery is in effect.

Method Two

Pdo_mysql The following operations are done under Linux system

1, download files or enter the PHP source package into the Ext/pdo_mysql

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

2, Extract files

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 installation in:/usr/local/php/mysql installed in:/usr/local/mysql compile time to pay attention to your own installation directory where

3, install to the PHP configuration

Keep this in mind, and then open the php.ini file,

and add a row

Extension=pdo_mysql.so

Windows PDO MySQL Extended installation

PHP.ini does not open the PDO, so modify the php.ini, will be shaped like the following code before removing the semicolon, modified as follows:

Extension_dir= "E:/amp/php/ext"//here is configured for your own ext directory path

......

Extension=php_mysql.dll

......

Extension=php_pdo.dll

......

Extension=php_pdo_mysql.dll

After restarting Apache, the access continues to report the following error:

Cdbconnection cannot open database connection: Could not find driver

It means that you can't find the database driver, and I looked at it with Phpinfo, and PDO really turned on, but PDO the database supported in that item shows no value, which means that the php_pdo_mysql.dll extension cannot be loaded. After several attempts, including replacing the version of PHP, replace the MySQL version. But none worked. Can't you really turn on PHP's MySQL PDO extension?

I checked it on the Internet, and I finally found a solution.

Method One: You need to add the path of the PHP installation directory to the system environment variable path, which solves the problem.

Method Two: Because I was deployed on the server, running the server, so can not reboot, so you can also copy the PHP installation directory Libmysql.dll under the Windows directory

Restart Apache

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.