PHP to properly configure MySQL detailed tutorial

Source: Internet
Author: User
Tags ini php file

But today in a CMS, there is an unforgivable error, unable to connect to MySQL, wrote a test MySQL PHP file as follows:

The code is as follows Copy Code
<?php
$link =mysql_connect (' localhost ', ' root ', ' root ');
if (! $link) echo "Failed!";
else echo "Success!";
Mysql_close ();
?>

Results reported errors: Fatal error:call to undefined function mysql_connect (), obviously unable to find the corresponding library of MySQL, Baidu a lot of, is what copy MySQL Lib library, is also copied to Windows System32 directory, too complex, in fact, the correct configuration should be in the Apache httpd.conf file to add the settings:

The code is as follows Copy Code

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

Note that the last line is the key, tell Apache where your PHP configuration file is, or you'll have to copy the php.ini file to the Windows system directory. In general, we can complete the combination of Apache and PHP through this configuration. And in the php.ini file only need to modify the following several places to:

# Modify PHP's extension library directory for your actual path

The code is as follows Copy Code
Extension_dir = "D:/tools/php-5.3.1/ext"

# Remove the front;

The code is as follows Copy Code
Extension=php_mysql.dll

The final step is to add your PHP installation path to the system environment variable (note the system environment variable, not the user environment variable) path, and after the setup succeeds, the phpinfo () should be available in Apache Environment section of the path can be seen in your PHP installation directory, otherwise the environment variable is not configured successfully (note, configure the environment variable restart Apache).

Complete these steps can be correctly connected to the database, but the premise is that your Apache and PHP integration is normal, and then consider this MySQL configuration, if you can not reach the effect, you may query me, hehe!


To summarize, the correct configuration steps for the integration of Apache and PHP (including MySQL) under Windows platform are as follows:

1, the installation of Apache, and to ensure that Apache can operate independently

2, the PHP (such as 5.2.17 or 5.3.1) to extract the ZIP package to a directory, such as d:php-5.3.1

3, at the end of the Apache httpd.conf file add the following paragraph:

The code is as follows Copy Code
# php5 Supportloadmodule php5_module D:/php-5.3.1/php5apache2_2.dll
The code is as follows Copy Code
AddType application/x-httpd-php. php
The code is as follows Copy Code
Phpinidir d:/php-5.3.14

, add the d:/php-5.3.1 path to the path of the operating system's environment variable (which must be a system variable rather than a user variable)

5, the PHP installation directory under the php.ini-dist renamed to PHP.ini, and modify the following:

# Set up PHP's extended file directory

The code is as follows Copy Code
Extension_dir = "D:/php-5.3.17/ext"

# Open the MySQL extension, remove the front;

  code is as follows copy code
extension=php _mysql.dll
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.