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

People, I try to run the basic php script on the cmd command line, which connects to the sql server 2012 on my local computer, it gives me the following error ... "PHP Fatal error: call undefined function mssql_select_db () in c: ... appscript.php on line 16 "

Here is my script, I am not very familiar with php, but played with it, and I'm not sure 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 healthy if someone can help or at least give me some pointers.

0
source share
2 answers

You seem to be using the wrong functions. You should only use functions from http://www.php.net/manual/en/function.sqlsrv-begin-transaction.php

There seems to be no need to select db (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 the PHP manual because some functions may be missing.

+2
source

You need to enable the MSSQL extension.

http://www.php.net/manual/en/mssql.installation.php

+1
source

Source: https://habr.com/ru/post/908297/


All Articles