If you are experiencing "access denied" errors when trying to establish a MySQLi connection in PHP5 but have no issues with the deprecated MySQL extension, it's likely due to differences in how each extension handles the connection and authentication process.

PHP5 has two primary MySQL extensions: the original MySQL extension and the improved MySQLi extension (MySQL Improved). The original MySQL extension is deprecated and should not be used anymore due to security and performance issues. It's essential to switch to the MySQLi or PDO (PHP Data Objects) extension for better security and support for modern MySQL features.

Here are some possible reasons for the "access denied" error with MySQLi:

  1. Different Authentication Methods: MySQLi and the original MySQL extension may use different authentication methods. If your MySQL server is configured with strict authentication settings, it's possible that the credentials used by MySQLi are not matching the ones accepted by the server. Make sure the username, password, and hostname used in both connections are the same.

  2. User Privileges: Check if the user used in the MySQLi connection has sufficient privileges to access the database. MySQLi and MySQL extensions might use different user accounts, and the user for MySQLi might not have the necessary permissions.

  3. Host Access: Verify that the host from which you are trying to connect is allowed to access the MySQL server. Some servers restrict access to specific IP addresses, and if the IP address used by MySQLi is not allowed, it can result in an "access denied" error.

  4. MySQL Server Version: Ensure that your MySQL server version is compatible with the MySQLi extension. In rare cases, there might be compatibility issues between PHP5's MySQLi and the MySQL server version.

  5. Connection Error Handling: Check your PHP code for proper error handling when establishing the MySQLi connection. Make sure to capture any connection errors and display or log them to identify the specific issue.

Given that PHP5 and the original MySQL extension are deprecated and no longer maintained, it's highly recommended to upgrade to PHP7 or higher and use MySQLi or PDO for database connections. Additionally, ensure that your MySQL server is running a supported version with up-to-date security settings.

Remember that deprecated extensions are no longer suitable for production environments due to potential security vulnerabilities and lack of support. Upgrading to a newer PHP version and using modern database extensions will provide better performance, security, and compatibility.

Have questions or queries?
Get in Touch