PHP中PDO_MYSQL扩展安装的2种方法
PHP中PDO_MYSQL扩展安装的2种方法
方法一
看到CakePHP文档要求安装pdo_mysql扩展,于是就尝试安装了一下。
这里我的系统是CentOS 6.0。如果你的系统是其他版本的Linux/Unix,可以参考。如果你的系统是Windows的,抱歉,以下内容不适合你,请移步。
首先是下载pdo_mysql扩展的源码包。下载页面在这里:http://pecl.php.net/package/PDO_MYSQL。可以先下载了然后用FTP传到服务器。
我是在复制了下载地址以后使用wget直接下载到服务器端的。
# wget http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
然后是解压缩。
# tar -zxvf PDO_MYSQL-1.0.2.tgz
进入解压后的目录,然后执行phpize。
# /usr/local/php/bin/phpize
Configuring for:
PHP Api Version: 20100412
Zend Module Api No: 20100525
Zend Extension Api No: 220100525
下面生成makefile。后面的两个参数必须要添加,一开始我没有添加,结果分别都提示找不到php-config和mysql的header文件。
# ./configure –with-php-config=/usr/local/php/bin/php-config –with-pdo-mysql=/usr/local/mysql
在make之前还要做一个mysql的header文件的软连接。因为mysql安装的时候指定了目录,不做软连接的话,还是找不到header文件。
# ln -s /usr/local/mysql/include/* /usr/local/include/
然后make和make install。
# make
# make install
之后会提示如下,意思是扩展被安装到了如下目录里。
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20100525/
为了方便,我把pdo_mysql.so文件移动到extensions目录下。
# mv /usr/local/php/lib/php/extensions/no-debug-zts-20100525/pdo_mysql.so /usr/local/php/lib/php/extensions/
随后就可以修改php.ini文件了。
找到; extension_dir = “./”这一行,去掉注释,并修改路径。
extension_dir = “/usr/local/php/lib/php/extensions/”
这里经过我测试,发现php只会从该目录寻找扩展so,而并不寻找该目录下的子目录。所以之前我为了统一管理,把so文件都移动到该目录下。
找到; extension=php_pdo_mysql.dll这一行,去掉注释,并修改后面的文件名。
extension=pdo_mysql.so
文件名不太一样,这里要把php_前缀去掉,否则找不到文件。后面的dll是windows下的文件名,我们改成so。
最后重启apache就可以了。用phpinfo()查看发现已经生效了。
方法二
PDO_MYSQL以下操作都在Linux 系统下操作
1、下载 文件 或者 进入 在PHP源码包中进入ext/pdo_mysql
http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
2、解压文件
tar zxvf PDO_MYSQL-1.0.2.tgz
3、配置和编译文件
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
注: 我的PHP安装在 : /usr/local/php/ mysql 安装在 : /usr/local/mysql 编译的时候注意你自己的安装目录在哪里
3、安装到PHP配置下
把这个记住,然后打开 php.ini文件,
并添加一行
extension=pdo_mysql.so
windows PDO MYSQL扩展安装
php.ini中没有开启pdo,故修改php.ini,将形如下面的代码前面去掉分号,修改后如下:
extension_dir="E:/amp/php/ext" //这里配置为你自己的ext目录路径
......
extension=php_mysql.dll
......
extension=php_pdo.dll
......
extension=php_pdo_mysql.dll
重启apache后访问又继续报以下错误:
CDbConnection 无法开启数据库连线: could not find driver
意思是无法找到数据库驱动,我又用phpinfo看了一下,PDO确实是开启了,但是PDO那一项中支持的数据库显示no value,说明无法加载php_pdo_mysql.dll这个扩展。经过多次尝试,包括更换php的版本,更换mysql的版本。但是均不奏效。难道真的无法开启php的mysql pdo扩展了吗?
在网上查了又查,终于找到解决方案
方法一:需要把php安装目录的路径加入到系统环境变量PATH中,这样就可以解决问题。
方法二:因为我是在服务器上部署的,正在运行着的服务器,所以无法重启,故也可将php安装目录下的libmysql.dll复制到windows目录下
重启apache

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

I encountered a tricky problem when developing a small application: the need to quickly integrate a lightweight database operation library. After trying multiple libraries, I found that they either have too much functionality or are not very compatible. Eventually, I found minii/db, a simplified version based on Yii2 that solved my problem perfectly.

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.
