MySQL is a widely used relational database management system. It is an important part of database technology in Internet companies and enterprises and institutions. As a developer, if you want to use or develop MySQL-related applications, you need to use MySQL's API to operate MySQL. The API of MySQL is provided in the form of extension and needs to be installed manually in the PHP-CGI environment.
This article will introduce how to install the MySQL extension in the Windows PHP-CGI environment.
Confirm environment
First you need to confirm the current PHP version and system CPU architecture version, which can be achieved through the phpinfo function. The specific operation is to write a phpinfo.php file with the following content:
<?php phpinfo(); ?>
Then place the phpinfo.php file in the root directory of the website, access the file, and you will see information about the current Environment details.
After downloading the file, copy the MySQL extension file to the PHP extension directory. The extension directory is in the phpinfo() function. You can view the directory corresponding to the extension_dir key value in the php.ini file listed in the Loaded Configuration File column. Generally, this directory is the ext folder under the PHP installation directory.
Modify the php.ini file
Open the php.ini file and add the following configuration information to the end of the file:
[MySQL] mysql.default_socket = "mysql服务器的socket文件地址" extension=php_mysql.dll
Among them, mysql.default_socket is the MySQL server The socket file address. This value can be found in the phpinfo() function and obtained through the mysql.default_socket sale under the MySQL module. This value is consistent with the value corresponding to the variable socket in the my.cnf configuration file of the MySQL server.
Check whether the MySQL module is effective
Write a PHP script file for testing. The content of the file is as follows:
<?php //连接MySQL数据库 $link = mysql_connect("localhost","root","123456"); //检查是否连接成功 if (!$link) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; mysql_close($link); ?>
After running the file, if Connected successfullylly is output, it means that the MySQL module has been successfully installed.
Conclusion:
Through the above steps, we can complete the installation of the MySQL extension in the Windows PHP-CGI environment. In actual applications, MySQL extensions can also be installed in other ways, such as compiling and installing from PHP source code, or installing through PECL. However, no matter which method is used, as long as the MySQL extension can be successfully installed, you can easily use the MySQL database in the PHP-CGI environment, providing convenience for web development.
The above is the detailed content of mysql extension installation. For more information, please follow other related articles on the PHP Chinese website!