PHP正确配置mysql 详解教程
php将可以正常的和apache结合,并且常见的诸如:PHP Warning: PHP Startup: Unable to load dynamic library……、Fatal error: Call to undefined function mysql_connect() 错误
不过今天在弄一个CMS时还是出现了一个不可饶恕的错误,无法连接mysql,写了一个测试mysql的php文件如下:
代码如下 | 复制代码 |
$link=mysql_connect('localhost','root','root'); if(!$link) echo "失败!"; else echo "成功!"; mysql_close(); ?> |
结果报错误:Fatal error: Call to undefined function mysql_connect(),明显没法找到mysql相应的库,百度了一大堆,又是什么复制mysql的lib库、又是复制到windows的system32目录,过于复杂,其实正确的配置应该是在apache的httpd.conf文件中加入下设置:
代码如下 | 复制代码 |
LoadModule php5_module d:/tools/php-5.3.1/php5apache2_2.dll |
注意,最后一行是关键,告诉apache你的php配置文件在哪里,不然你就得把php.ini文件复制到windows的系统目录下了。一般我们通过这里配置就可以完成apache和php的结合。而在php.ini文件中只需要修改如下几个地方即可:
# 修改php的扩展库目录为你的实际路径
代码如下 | 复制代码 |
extension_dir = "D:/tools/php-5.3.1/ext" |
# 去掉前面的;
代码如下 | 复制代码 |
extension=php_mysql.dll |
最后一个步骤就是在系统环境变量(注意是系统环境变量,而非用户环境变量)path中加入你的PHP安装路径,在设置成功后,通过phpinfo()应该可以在Apache Environment段的path中可以看到你的PHP安装目录,否则就是环境变量没有配置成功(注意,配置环境变量后重启下apache)。
完成这些步骤后就可以正确连接数据库了,不过前提是你的apache和php的整合是正常的,然后再考虑这个mysql配置,如果还不能够达到效果,你可以质问我,呵呵!
总结,windows平台下apache和php(包括mysql)整合的正确配置步骤如下:
1、安装apache,并保证apache可以单独正常运行
2、将php(如5.2.17或5.3.1)的zip包解压到一个目录,比如D:php-5.3.1
3、在apache的httpd.conf文件的最后加入如下段:
代码如下 | 复制代码 |
# php5 supportLoadModule php5_module D:/php-5.3.1/php5apache2_2.dll |
代码如下 | 复制代码 |
AddType application/x-httpd-php .php |
代码如下 | 复制代码 |
PHPIniDir D:/php-5.3.14 |
、在操作系统的环境变量(必须是系统变量而非用户变量)的path中加入D:/php-5.3.1路径
5、将php安装目录下的php.ini-dist重命名为php.ini,并修改如下内容:
# 设置php的扩展文件目录
代码如下 | 复制代码 |
extension_dir = "D:/php-5.3.17/ext" |
# 开启mysql扩展,去掉前面的;注释
代码如下 | 复制代码 |
extension=php_mysql.dll |

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.

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.

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.

The process of starting MySQL in Docker consists of the following steps: Pull the MySQL image to create and start the container, set the root user password, and map the port verification connection Create the database and the user grants all permissions to the database

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

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.

PHP is a server-side scripting language used for dynamic web development and server-side applications. 1.PHP is an interpreted language that does not require compilation and is suitable for rapid development. 2. PHP code is embedded in HTML, making it easy to develop web pages. 3. PHP processes server-side logic, generates HTML output, and supports user interaction and data processing. 4. PHP can interact with the database, process form submission, and execute server-side tasks.

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.
