Home  >  Article  >  Database  >  mysql extension installation

mysql extension installation

WBOY
WBOYOriginal
2023-05-14 11:32:37826browse

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.

  1. 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.

  1. Download the MySQL extension file
    According to the confirmed PHP version and system CPU architecture version, download the corresponding version of the MySQL extension file from the official website. The download address is: https://dev.mysql.com/downloads

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.

  1. 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.

  2. Restart the Web server
    Before the configuration takes effect, you need to restart the Web server to make the configuration file update take effect.
  3. 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!

Statement:
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