1

Iam so fresh with PHP so this problem so big to me. I dont know why and where my mistake is. Based on my research to connect to MSSQL database by using this code:

<?php
$run = mssql_connect('dev-svr05','sa','P@55w0rd', 'orlig_sm_dev');
if ($run)
{
    echo "Connection OK";
}
else
{
    echo "Connection Failed";
}
?>

But when i run this code i got this error message:

PHP Fatal error: Call to undefined function mssql_connect() in C:\Inetpub\wwwroot\phpscript\save_mssql.php on line 5 

I using the same code to connect to MYSQL and its success but not with MSSQL. Can anybody please tell me why this is happen? Thank You

3
  • I guess you have not installed PECL odbtp >= 1.1.1 Commented Apr 14, 2015 at 10:46
  • Thanks for your response. Could you please guide how to install PECL odbtp >= 1.1.1 Commented Apr 15, 2015 at 2:13
  • read this page. Commented Apr 15, 2015 at 5:10

3 Answers 3

1

I would advice you download the sql server binaries from windows and use PDO.

try { 
        //In some occasions you only need to define IP/Hostname and you can forgo the \SQLEXPRESS part
        $db = new PDO( "sqlsrv:Server=HOSTNAME\SQLEXPRESS;Database=DATABASENAME","USERNAME","PASSWORD");
       $db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
       // set this to your primary database
      $db->query("USE DATABASENAME");
    }

    catch( PDOException $e ) { 

       die( "Error connecting to SQL Server".$e ); 
    }
Sign up to request clarification or add additional context in comments.

Comments

0

Fourth parameter is expecting a true/false. Refer the below link and try: http://php.net/manual/en/function.mssql-connect.php

Comments

0

Try "sqlsrv_connect" instead of "mssql_connect"

1 Comment

Tried it. same error. PHP Fatal error: Call to undefined function sqlsrv_connect() in C:\Inetpub\wwwroot\phpscript\save_mssql.php on line 14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.