Home > PHP > Connecting to SQL Server 2005 Express using PHP

Connecting to SQL Server 2005 Express using PHP

Bạn sử dụng php để kết nối tới SQL Server 2005 nhưng lại nhận được lỗi :

mssql_connect() [function.mssql-connect]: Unable to connect to server…

Để giải quyết vấn đề này bạn có thể làm theo một số bước sau :

Bước 1 : Bật extention php_mssql lên :

Nếu bạn sử dụng wamp thì có thể vào PHP–> php extentions –> php_mssql

Nếu bạn sử dụng xampp thì bỏ comment dòng php_mssql.dll đi

Bước 2 : Bạn phải chắc chắn rằng SQL Server 2005 đang chạy đúng port chuẩn là 1433, và đã bật Name PipesTCP/IP.  đã bật chức năng remote connection

bạn có thể kiểm tra bằng cách telnet localhost 1433

nếu telnet thành công thì port đó đang mở

nếu không bạn có thể chỉnh lại như sau :

1. Start -> All Programs –> Microsoft SQL Server 2005 -> Configuration tools -> SQL Server Configuration Manager

2. Kích vào Protocols for SQL Express

3. Bật Name PipesTCP/IP lên

3. Kích chuột phải vào phần TCP/IP –> Properties

4. Trong tab Ip Address kéo xuống cuối, chỉnh lại TCP/IP port là 1433

5. Khởi động lại SQL Server 2005 bằng cách gõ vào Command prompt :

net stop mssql$sqlexpress

net start mssql$sqlexpress

có thể xem thêm ở đây để rõ hơn:

http://kimphuc.wordpress.com/2009/10/18/enable-sa-user-and-remote-connection-from-sql-server-2005/

Bước 3 :

1. Bạn tải file ntwdblib.dll (2000.80.194.0) tại đây hoặc có thể tìm trên một số trang download dll như  http://www.dll-files.com hoặc www.dll-download.net

2. Ghi đè  vào file C:\wamp\bin\apache\apache2.2.6\bin\ntwdblib.dll

3. Ghi đè vào file : C:\wamp\bin\php\php5.2.5\ntwdblib.dll

Bước 4 :

Khởi động lại các dịch vụ

Good Luck!

Advertisement
Categories: PHP
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.