PHP data object PDO extension defines a lightweight and consistent interface to access to the PHP database. PDO provides an abstract layer for data, which means that no matter no matter what database you use, you can query and retrieve data using the same functions (methods).
Linux
1. CentOS
Environment
Websever:Centos6.5 (virtual machine demo)
PHP package :/data/php-5.6.14/
PHP installation:/usr/local/php/
mysql installation:/usr/local/mysql/
Workflow
Use phpinfo() to check whether the webserver has PDO installed. If no PDO is found, follow the steps below to install.
Find your PHP installation package(e.g. in the directory of /data/PHP-5.6.14/), and go to the directory of pdo_mysql. Execute
/usr/local/php/bin/phpize(/usr/local/php/ is the directory where I installed my PHP. Set your path according to your situation.)
After executing the command above, a file is added to the directory of pdo_msyql.
Execute the command below
./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql/Note:
--with-php-config=/usr/local/php/bin/php-config is the configuration of installing PHP
--with-pdo-MySQL=/usr/local/mysql/ is to designate the installation directory for MySQL
(Set the installation directories of PHP and msyql according to your environment.)
Compile and install
make && make install
After executing the command and it will be like the screenshot shown below,
The directory in the last line of the screenshot will be user later. pdo_mysql.so is in that directory shown below.
Alter the configuration file of PHP, php.ini and add the code belwo to it.
extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/pdo_mysql.so
Save, quit, and restart. Run phpinfo() to check whether PDO is installed. If it is as shown below, it means that PDO is installed.
2. Ubuntu系统
sudo apt-get install php5-dev sudo apt-get install php5-pear sudo apt-get install libmysqlclient15-dev
Run pecl to install it
sudo pecl install pdo
Add extension=pdo.so to PHP configuration file.
Install pdo_mysql
sudo pecl install pdo_mysql sudo apt-get install php5-mysql
Add extension=pdo.so to PHP configuration file.
Restart it.
Windows
Alter php.ini and remove ";"
extension_dir="" // Set your own directory of ext extension=php_mysql.dll extension=php_pdo.dll extension=php_pdo_mysql.dll
Add the directory of PHP installation to the system variable PATH.
Restart it.