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

Windows Server2008下PHP7.2.4+Apache2.4调用srv_connect()报错求助

Hey there, let's fix that "call to undefined function srv_connect()" error you're hitting when trying to connect to SQL Server with CodeIgniter on Windows Server 2008. This issue almost always boils down to missing or misconfigured SQL Server extensions for PHP—here's a step-by-step breakdown to get you sorted:

Step 1: Grab the Correct SQL Server PHP Extensions

PHP 7.2 requires a specific version of the SQL Server drivers. You'll need the thread-safe (TS) versions of both php_sqlsrv and php_pdo_sqlsrv that match your PHP architecture (x86 or x64) and PHP 7.2. These are part of Microsoft's official SQL Server Driver for PHP.

Make sure you download the right package—look for files named something like php_sqlsrv_72_ts.dll and php_pdo_sqlsrv_72_ts.dll.

Step 2: Install the Extensions

Copy the downloaded .dll files into your PHP installation's ext directory (usually something like C:\PHP\ext if you installed PHP to the root of C:).

Step 3: Update Your php.ini Configuration

Open your php.ini file (found in your PHP install directory) and add these two lines to enable the extensions:

extension=php_sqlsrv.dll
extension=php_pdo_sqlsrv.dll

Double-check that your extension_dir setting is pointing correctly to the ext folder. It should look like either:

extension_dir = "ext"

Or the full absolute path:

extension_dir = "C:\PHP\ext"
Step 4: Restart Apache

Don't skip this! Changes to php.ini won't take effect until you restart your Apache server. You can do this via the Windows Services console (search for "Services" in the start menu) or using Apache's own control panel.

Step 5: Verify the Extensions Are Loaded

Create a simple PHP file named phpinfo.php in your WWW directory with this content:

<?php phpinfo(); ?>

Access it via your browser (e.g., http://your-server/phpinfo.php) and search for sqlsrv and pdo_sqlsrv. If you see dedicated sections for both, the extensions are loaded correctly.

Step 6: Double-Check Your CodeIgniter Database Config

Head to your CodeIgniter application's application/config/database.php file and make sure your database settings use the sqlsrv driver. Here's a sample config to reference:

$db['default'] = array(
    'dsn'   => '',
    'hostname' => 'your_sql_server_hostname_or_ip',
    'username' => 'your_sql_server_username',
    'password' => 'your_sql_server_password',
    'database' => 'your_target_database',
    'dbdriver' => 'sqlsrv', // This is critical—don't use mssql or other drivers!
    'dbprefix' => '',
    'pconnect' => FALSE,
    'db_debug' => (ENVIRONMENT !== 'production'),
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt' => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array(),
    'save_queries' => TRUE
);
Step 7: Install the Required ODBC Driver

The SQL Server PHP extensions depend on the Microsoft ODBC Driver for SQL Server. For Windows Server 2008, you'll need Microsoft ODBC Driver 13.1 or later (older versions don't support PHP 7.2). Install this driver if you haven't already—without it, the PHP extensions won't load properly.

If you've followed all these steps and still run into issues, double-check that your PHP 7.2.4 build is indeed thread-safe (Apache typically uses TS builds), and that all downloaded extensions match your PHP's architecture (x86 vs x64).

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 03:26:47