PHP正确配置mysql(apache环境)
写了一个测试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
AddType application/x-httpd-php .php
PHPIniDir d:/tools/php-5.3.1
注意,最后一行是关键,告诉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 support
LoadModule php5_module D:/php-5.3.1/php5apache2_2.dll
AddType application/x-httpd-php .php
PHPIniDir D:/php-5.3.1
4、在操作系统的环境变量(必须是系统变量而非用户变量)的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
完成上面5个步骤后,你的php将可以正常的和apache结合,并且常见的诸如:PHP Warning: PHP Startup: Unable to load dynamic library……、Fatal error: Call to undefined function mysql_connect()……也将一去不复返了!^_^

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

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

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.

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.

Safely handle functions and regular expressions in JSON In front-end development, JavaScript is often required...

IIS and PHP are compatible and are implemented through FastCGI. 1.IIS forwards the .php file request to the FastCGI module through the configuration file. 2. The FastCGI module starts the PHP process to process requests to improve performance and stability. 3. In actual applications, you need to pay attention to configuration details, error debugging and performance optimization.

Analysis of the reason why Python script cannot be found when submitting a PyFlink job on YARN When you try to submit a PyFlink job through YARN, you may encounter...

Display and processing of percentage numbers in Java In Java programming, the need to process and display percentage numbers is very common, for example, when processing Excel tables...

In MySQL, the function of foreign keys is to establish the relationship between tables and ensure the consistency and integrity of the data. Foreign keys maintain the effectiveness of data through reference integrity checks and cascading operations. Pay attention to performance optimization and avoid common errors when using them.
