Home php教程 php手册 PHP正确配置mysql 详解教程

PHP正确配置mysql 详解教程

Jun 13, 2016 am 10:08 AM
apache mysql php Can and Will common Tutorial normal correct of combine Detailed explanation Configuration

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
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 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
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP: Handling Databases and Server-Side Logic PHP: Handling Databases and Server-Side Logic Apr 15, 2025 am 12:15 AM

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.

PHP's Purpose: Building Dynamic Websites PHP's Purpose: Building Dynamic Websites Apr 15, 2025 am 12:18 AM

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

PHP: Creating Interactive Web Content with Ease PHP: Creating Interactive Web Content with Ease Apr 14, 2025 am 12:15 AM

PHP makes it easy to create interactive web content. 1) Dynamically generate content by embedding HTML and display it in real time based on user input or database data. 2) Process form submission and generate dynamic output to ensure that htmlspecialchars is used to prevent XSS. 3) Use MySQL to create a user registration system, and use password_hash and preprocessing statements to enhance security. Mastering these techniques will improve the efficiency of web development.

PHP and Python: Code Examples and Comparison PHP and Python: Code Examples and Comparison Apr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP: An Introduction to the Server-Side Scripting Language PHP: An Introduction to the Server-Side Scripting Language Apr 16, 2025 am 12:18 AM

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.

How to build a Zookeeper cluster in CentOS How to build a Zookeeper cluster in CentOS Apr 14, 2025 pm 02:09 PM

Deploying a ZooKeeper cluster on a CentOS system requires the following steps: The environment is ready to install the Java runtime environment: Use the following command to install the Java 8 development kit: sudoyumininstalljava-1.8.0-openjdk-devel Download ZooKeeper: Download the version for CentOS (such as ZooKeeper3.8.x) from the official ApacheZooKeeper website. Use the wget command to download and replace zookeeper-3.8.x with the actual version number: wgethttps://downloads.apache.or

See all articles