"PHP致命错误:在第16行的c:\ ... appscript.php中调用未定义的函数mssql_select_db()" [英] "PHP Fatal error: Call to undefined function mssql_select_db() in c:\...appscript.php on line 16"
问题描述
伙计们,我试图在cmd提示符下运行基本的php脚本,该脚本连接到本地计算机上的sql server 2012,它给了我以下错误..."PHP致命错误:在c中调用未定义的函数mssql_select_db() :... appscript.php,第16行"
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"
这是我的脚本,我对php不太熟悉,但是一直在玩它,并且不确定我的脚本是否正确..
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.
推荐答案
似乎您使用的是错误的函数.您应仅使用 http://www.php.net中的函数/manual/zh-CN/function.sqlsrv-begin-transaction.php
It seems you are using wrong functions. You should use only functions from http://www.php.net/manual/en/function.sqlsrv-begin-transaction.php
似乎没有必要选择db(没有sqlserv_select_db函数).
It seems there is no need to select db (there is no sqlserv_select_db function).
您应该将mssql_query更改为sqlsrv_query,其他功能也应相同,并且应查看PHP手册,因为某些功能可能会丢失.
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.
这篇关于"PHP致命错误:在第16行的c:\ ... appscript.php中调用未定义的函数mssql_select_db()"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!