"PHP Fatal error: Call to undefined function mssql_select_db() in c:\...appscript.php on line 16"
Asked Answered
T

2

0

Folks, Im trying to run a basic php script in cmd prompt which connects to sql server 2012 on my local machine, its gives me the following error..."PHP Fatal error: Call to undefined function mssql_select_db() in c:...appscript.php on line 16"

Here is my script, im not very familiar with php but have been playing around with it and im unsure if my script is correct..

  <?php
    $Server = "";
    $User = "";
    $Pass = "";
    $DB = "";

    //$SQLKEY = "";

    //connection to the database
    //$dbconn = sqlsrv_connect($Server, $User, $Pass)
    $connectionInfo = array("UID" => $User, "PWD" => $Pass, "Database" => $DB);
    $conn = sqlsrv_connect( $Server, $connectionInfo);
    //or die("Couldn't connect to SQL Server on $Server");

   //select a database to work with
    $selected = mssql_select_db($DB, $connectionInfo)
   or die("Couldn't open database $myDB");

   //declare the SQL statement that will query the database
   $query = "SELECT name from test ";

   //execute the SQL query and return records
  $result = mssql_query($query);

  $numRows = mssql_num_rows($result);
   echo "<h1>" . $numRows . " Row" . ($numRows == 1 ? "" : "s") . " Returned </h1>";

  //display the results
  while($row = mssql_fetch_array($result))
  {
    echo "<br>" . $row["name"];
  }
  //close the connection
  mssql_close($dbconn);
  ?>

Be great if someone could help or least give me a few pointers.

Tailrace answered 5/5, 2014 at 14:30 Comment(0)
I
2

It seems you are using wrong functions. You should use only functions from http://www.php.net/manual/en/function.sqlsrv-begin-transaction.php

It seems there is no need to select db (there is no sqlserv_select_db function).

You should change your mssql_query to sqlsrv_query and the same for other functions and you should look at PHP manual because some functions may missing.

Itu answered 5/5, 2014 at 14:45 Comment(2)
is there any way i can print a query or something from the database so that i confirm that the script is working, it says connection established but just to verify access aswell? cheersTailrace
Of course you have query method so you can get something from database table. Just look at php.net/manual/en/function.sqlsrv-query.php for examplePredicable
A
1

You need to enable the MSSQL extension.

http://www.php.net/manual/en/mssql.installation.php (dead link)
Last working version captured by archive.org: https://web.archive.org/web/20200920214312/http://www.php.net/manual/en/mssql.installation.php

Amil answered 5/5, 2014 at 14:32 Comment(2)
Im using the extension php_sqlsrv_53_nts.dll because the php version im using doesnt support mssql extension....Tailrace
What version are you using? #9987304 might help as wellAmil

© 2022 - 2024 — McMap. All rights reserved.