- 1 year ago
Trying to connect from PHP 7.1.3 to MYSQL 5.7.31 on Windows 10
To connect from PHP 7.1.3 to MySQL 5.7.31 on Windows 10, you'll need to ensure that the necessary PHP extensions for MySQL are installed and properly configured. Here's a step-by-step guide to help you get started:
Install PHP: Make sure you have PHP 7.1.3 or a compatible version installed on your Windows 10 machine. You can download PHP from the official PHP website (https://www.php.net/downloads.php) and follow the installation instructions.
Install MySQL: Download and install MySQL 5.7.31 or a compatible version for Windows from the official MySQL website (https://dev.mysql.com/downloads/mysql/). Follow the installation instructions and set up the MySQL server on your machine.
Configure PHP.ini: Locate the
php.ini
configuration file for your PHP installation. By default, it is typically located in the PHP installation directory. Openphp.ini
in a text editor and make the following changes:- Uncomment the line
extension=mysqli
by removing the semicolon (;
) at the beginning of the line. - Save the changes and close the file.
- Uncomment the line
Restart the web server: Restart your web server (e.g., Apache or Nginx) to apply the changes to the PHP configuration.
Test the connection: Create a PHP script (e.g.,
test.php
) with the following content to test the MySQL connection:php<?php
$host = 'localhost';
$user = 'your_mysql_username';
$password = 'your_mysql_password';
$database = 'your_mysql_database';
$conn = mysqli_connect($host, $user, $password, $database);
if (!$conn) {
die('Failed to connect to MySQL: ' . mysqli_connect_error());
}
echo 'Connected successfully to MySQL';
mysqli_close($conn);
?>
Replace
'your_mysql_username'
,'your_mysql_password'
, and'your_mysql_database'
with the appropriate values for your MySQL setup.Save the
test.php
file in the web server's document root folder.Open a web browser and access the
test.php
file through the local web server (e.g.,http://localhost/test.php
). If everything is configured correctly, you should see the "Connected successfully to MySQL" message.
By following these steps, you should be able to connect from PHP 7.1.3 to MySQL 5.7.31 on your Windows 10 machine. Ensure that the MySQL server is running and that the provided MySQL credentials are correct.