0

I have used the following php code to show the number of rows from sql table but I am getting below error message.

Fatal error: Call to undefined function mssql_query()
             in D:\wamp\www\thereport24\gp.php
             on line 22

my code:

$conn = odbc_connect('gpcon','',''); 
if ($conn)
    {
    $query= "select * from SubscriberServices where SubscriptionGroupID like 'ms_gp_tr24bn_3333'";
    $results = mssql_query($query);
    $rows    = mssql_fetch_array($results);
    echo $rows[0];
    mssql_close($con); 
}
6
  • 3
    check if extension=php_mssql.dll is uncommented in your php.ini and mssql installed on your machine Commented Nov 8, 2014 at 12:18
  • @bigbobr , check if extension=php_mssql.dll ...it is done ...mssql already installed...but i m getting same error... Commented Nov 8, 2014 at 14:06
  • possible duplicate of Can't connect to sql from php script Commented Nov 8, 2014 at 17:19
  • @Max...i have follow it ...but facing same problem...what is it real solution.. Commented Nov 8, 2014 at 18:41
  • Have you restarted Apache/PHP? Can you call php_info() and see if the right extensions are indeed loaded? Commented Nov 8, 2014 at 21:00

1 Answer 1

0

If you use sql server, use this code. This works for me:

<?php
    $serverName = "serverName"; 
    $options = array(  "UID" => "sa",  "PWD" => "Password",  "Database" => "DBname");
    $conn = sqlsrv_connect($serverName, $options);

    if( $conn ) {
         echo "Connection established.<br />";

         $query="select * from SubscriberServices where SubscriptionGroupID like 'ms_gp_tr24bn_3333'";
         $result = sqlsrv_query($conn,$query);
         sqlsrv_close($conn);


    }else{
         echo "Connection could not be established.<br />";
         die( print_r( sqlsrv_errors(), true));
    }

?>

if it returns "Connection established." it's mean you install MS SQL Drivers correct.

Sign up to request clarification or add additional context in comments.

Comments

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.