求助:PHP5.6环境下Code Igniter3.1.8与SQL Server2000连接方案
Hey there, let's work through this connection issue together. The core problem here is likely driver compatibility—SQL Server 2000 is extremely outdated, and the sqlsrv driver you're using doesn't support it. Here's how to fix it step by step:
1. Swap to a Supported Driver
Microsoft's sqlsrv driver only supports SQL Server 2005 and newer. For SQL Server 2000, you need to use either dblib (based on FreeTDS) or odbc. Let's start with the most reliable option for your setup:
Option A: Use dblib Driver
First, make sure your PHP 5.6 installation has the pdo_dblib or mssql extension enabled (the mssql extension works for PHP 5.x, though it's deprecated in newer versions). Then update your database config:
$db['default'] = array( 'dsn' => '', 'hostname' => '200.200.200.242\SERVERBARU', 'port' => '1433', 'username' => 'sa', 'password' => 'm45t3r', 'database' => 'DEPO2017', 'dbdriver' => 'dblib', // Replace sqlsrv with dblib here '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 );
If you're on Linux, you'll need to install the FreeTDS library first:
# For Ubuntu/Debian sudo apt-get install freetds-dev freetds-bin
For Windows, download the FreeTDS driver and configure your freetds.conf file to target SQL Server 2000:
[SERVERBARU] host = 200.200.200.242 port = 1433 tds version = 8.0 # TDS 8.0 is for SQL Server 2000
Option B: Use odbc Driver
If dblib gives you trouble, try ODBC. You'll need the legacy SQL Server 2000 ODBC driver installed on your server. Update your config like this:
$db['default'] = array( 'dsn' => 'Driver={SQL Server};Server=200.200.200.242\SERVERBARU;Database=DEPO2017;', 'username' => 'sa', 'password' => 'm45t3r', 'dbdriver' => 'odbc', // Keep the rest of your config settings the same );
2. Verify SQL Server 2000 Settings
Even with the right driver, you might hit network/permission blocks:
- Enable remote connections: Open SQL Server Enterprise Manager, right-click your server → Properties → Connections → Check "Allow remote connections to this server".
- Set mixed authentication mode: Go to Security → Server Authentication → Select "SQL Server and Windows Authentication Mode" (since you're using the
saaccount). - Check port accessibility: Confirm port 1433 is open on the SQL Server machine, and your PHP server can ping
200.200.200.242.
3. Debug with Error Messages
Enable db_debug to get specific error details (only do this in non-production environments!). The error message will tell you exactly what's wrong—whether it's a missing driver, invalid credentials, or network issue.
内容的提问来源于stack exchange,提问作者BARI ANTO

