Heim > Artikel > Backend-Entwicklung > Wie installiere und konfiguriere ich MySQLi für PHP unter macOS?
Setting Up MySQLi for PHP on macOS
For those facing difficulties installing MySQLi on their Mac environment, this guide provides step-by-step instructions to simplify the process.
Prerequisites:
Installation Process:
Install php-mysqlnd:
Php-mysqlnd is a drop-in replacement for php-mysql, offering better performance and stability. To install it, run the following command:
brew install php@7.4 --with-mysqlnd
Replace "php@7.4" with the version of PHP you have installed.
Enable MySQLi Extension:
After installing php-mysqlnd, you need to enable the MySQLi extension in your PHP configuration. Edit the following file based on your OS version:
Add or uncomment the following line:
extension=mysqli.so
Restart Apache:
After making the changes to the php.ini file, restart Apache to apply them:
sudo apachectl restart
Testing MySQLi:
To verify that MySQLi is installed and configured correctly, create a simple PHP script:
<?php $mysqli = new mysqli("localhost", "username", "password", "database"); if ($mysqli->connect_errno) { echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error; } else { echo "Connection to MySQL server succeeded."; } ?>
Run the script to check if it connects to the MySQL database without any errors.
Das obige ist der detaillierte Inhalt vonWie installiere und konfiguriere ich MySQLi für PHP unter macOS?. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!