You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PHP 7.4无法加载php_mysqli.dll动态库,MySQL连接失败求助

Troubleshooting PHP 7.4 mysqli.dll Loading Issues on Windows (And Eclipse Checks)

Let’s work through this systematically—first, let’s rule out system/PHP configuration problems before we focus on Eclipse, since DLL loading failures almost always start there, not the IDE.

First: Verify the Problem Isn’t With PHP/System Configuration

Start by testing outside of Eclipse to isolate the issue. Open Command Prompt and run these checks:

1. Confirm PHP Thread Safety (TS) vs Non-Thread Safety (NTS) Match

PHP 7.4 on Windows comes in two flavors, and the php_mysqli.dll must match your PHP build:

  • Run php -v in cmd. Look for "Thread Safe" in the output (e.g., PHP 7.4.33 (cli) (built: Aug 1 2023 11:50:48) ( ZTS Visual C++ 2017 x64 ) means Thread Safe).
  • Check your C:\Program Files\php\ext directory: the DLL should be compiled for the same TS/NTS mode. If you downloaded the wrong PHP package, even the correct path won’t work—re-download the matching PHP version from the official site.

2. Install Required Visual C++ Redistributable

PHP 7.4 depends on the Visual C++ Redistributable for Visual Studio 2017/2019 (VC15/VC16). Missing or outdated versions will break DLL loading:

  • Download the x64 or x86 version matching your PHP architecture (check php -v for x64/x86) and install it. Restart your system after installation.

3. Fix Directory Permissions

The C:\Program Files folder is protected by Windows UAC, which might block PHP from reading the DLL files:

  • Copy your entire PHP directory to a non-system path like C:\php (avoid spaces in the path if possible, though PHP 7.4 handles them better than older versions).
  • Update your php.ini to set extension_dir = "C:\php\ext", then run php -m again to see if mysqli loads.

4. Validate PHP.ini Configuration

Double-check these settings in your active php.ini (run php --ini in cmd to confirm which php.ini PHP is using):

  • Ensure extension_dir points directly to your ext folder (use absolute paths, no trailing slashes).
  • Use the correct extension name: for PHP 7.4, it’s extension=mysqli (not extension=php_mysqli.dll—the .dll suffix is optional but often omitted in modern PHP configs).
  • Make sure there’s no semicolon (;) before the extension=mysqli line (that comments it out).

If CLI Works But Eclipse Doesn’t: Check Eclipse Configuration

If php -m shows mysqli is loaded correctly in the command line, then the issue is with Eclipse’s setup:

1. Confirm Eclipse is Using the Correct PHP Executable

  • Open Eclipse’s Window > Preferences > PHP > PHP Executables.
  • Verify the path points to your working PHP php.exe (the one you tested in cmd).
  • Check that the "PHP ini file" field points to the same php.ini you modified (not the default php.ini-development or php.ini-production unless you renamed one to php.ini).

2. Ensure Eclipse’s PHP Environment Matches CLI

  • Sometimes Eclipse uses a different PHP environment profile. Go to Run > Run Configurations, select your PHP script, and check the "PHP Executable" dropdown matches the working one from your cmd tests.

3. Clear Eclipse’s Cache

IDE caches can hold outdated config data:

  • Restart Eclipse with the -clean flag (open cmd, navigate to Eclipse’s installation folder, run eclipse.exe -clean).
  • Refresh your project: right-click the project in Eclipse’s Project Explorer > Refresh.

Final Note

If none of these steps work, try creating a simple test script (e.g., test.php with <?php phpinfo(); ?>) and run it via CLI (php test.php) to see if mysqli appears in the output. If it does, the problem is definitely Eclipse-specific—double-check all the IDE’s PHP settings again. If it still doesn’t load, you may need to re-download a fresh copy of PHP 7.4 (make sure to pick the correct TS/NTS and architecture) and start with a clean php.ini configuration.

内容的提问来源于stack exchange,提问作者StevieJ123

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.07 16:57:47