2

I have never connect PHP to MS sql server so getting confusion and trouble for configuring wamp to connect with sql server by following online tutorial. I have install wamp that consist of Apache Version 2.2.21 and PHP Version 5.3.8 and MS Sql server 2008 on same machine. I downloaded the Microsoft Drivers for PHP for SQL Server(SQLSRV20.EXE). and extracted the file to D:\wamp\bin\php\php5.3.8\ext. Then I opened the php.ini file from wamp icon tray and provide the extension path as extension=php_sqlsrv_53_ts_vc9.dll and extension=php_sqlsrv_53_nts_vc9.dll. I have put php file name testsqlserver.php in www root folder of wamp which code is shown below:

<?php
   $server = 'mypc/SQLEXPRESS';
   $link = mssql_connect($server,'sa','password');
   if(!$link)
   {
      die('something went wrong');
   }
?>       

When I called testsqlserver.php through browser as localhost:8080\testsqlserver.php. It shows the error: Fatal error: Call to undefined function mssql_connect() in D:\wamp\www\connectsqlserver.php

am I doing wrong way? or is there anything more to do for this.I have gone through different online search but unable to get the exact solution for this. Would someone help me, it would be great appreciation

hakre
  • 193,403
  • 52
  • 435
  • 836
Shrestha Sunil
  • 329
  • 4
  • 13
  • 28

3 Answers3

2

Microsoft Drivers for PHP for SQL Server which you have downloaded , support sqlsrv_connect() to establish connection with sql server database

You should use sqlsrv_connect() function to connect with sql server , mssql_connect is depreciated
you can get full list of function and their description form following link

http://msdn.microsoft.com/en-us/library/cc296152%28SQL.90%29.aspx

  • I have use following php script still saying same problem undefined function: $uid, "PWD" => $pwd , "Database"=>"IVRFlowManager"); $conn = sqlsrv_connect( $serverName, $connectionInfo); if( $conn ) { echo "Connection established.\n"; } else { echo "Connection could not be established.\n"; die( print_r( sqlsrv_errors(), true)); } sqlsrv_close( $conn); ?> – Shrestha Sunil May 24 '12 at 09:11
2

You have to edit your php.ini file located within the WAMP directory. There should be a few lines in there for loading the MS SQL extension but they are commented out; all you need to do is uncomment those lines and restart Apache.

I'm using XAMPP and the lines within my php.ini that I have to uncomment are:

;extension=php_mssql.dll

;extension=php_pdo_mssql.dll

  • ya, I uncomment those extension...... even it's showing same error:atal error: Call to undefined function mssql_connect() in D:\wamp\www\connectsqlserver.php on line 7 – Shrestha Sunil Jan 06 '12 at 09:28
-1

I do not currently use wamp, but I think you should enable PHP extensions for this. Click on wamp icon in status bar and enable php_mssql and php_pdo_mssql extensions, then restart apache service.

Irmantas
  • 86
  • 1
  • 9
  • Check this http://forum.ragezone.com/f724/get-wamp-work-mssql-673301/ forum post, maybe you would find something useful – Irmantas Jan 06 '12 at 11:38