我需要在PHP中使用SQLSERVER数据库为大学工作创建一个crud,用PHP连接银行我得到它,现在执行没有说明,请帮助我,我很难..?
我的代码
<? php
$ server = "DESKTOP-RA9T588";
$ conectioninfo = array ("Database" => "Banca_de_Revista", "UID" => "Arthur", "PWD" => "inter190744");
$ result = sqlsrv_connect ($ server, $ conectioninfo);
$ bank = "Banca_de_Revista";
$ db = mssql_select_db ($ bank, $ conmssql);
if ($ result && $ db) {
echo "Congratulations !! The connection to the database has occurred normally!";
} else {
echo ("Could not connect.");
die (print_r (sqlsrv_errors (), true));
}
?>
problemaqueestáaparecendo:
致命错误:调用未定义的函数mssql_select_db()
提前谢谢。
答案 0 :(得分:2)
函数sqlsrv_connect()
和mssql_select_db()
来自两个不同的PHP扩展。函数sqlsrv_connect()
来自SQLSRV扩展(用于MS SQL Server的PHP驱动程序),而函数mssql_select_db()
来自MSSQL扩展,在使用PHP 5.3或更高版本的Windows上不再可用。
这是一个非常简单的脚本,它显示了如何连接到MS SQL Server并执行简单查询:
<?php
$server = "DESKTOP-RA9T588";
$cinfo = array(
"Database" => "Banca_de_Revista",
"UID" => "Arthur",
"PWD" => "inter190744"
);
$conn = sqlsrv_connect($server, $cinfo);
if( $conn === false )
{
echo "Error (sqlsrv_connect): ".print_r(sqlsrv_errors(), true);
exit;
}
$sql =
"SELECT 'SUSER_SNAME' AS [NAME], CONVERT(varchar(128), SUSER_SNAME()) AS [VALUE]".
"UNION ALL ".
"SELECT 'SUSER_NAME' AS [NAME], CONVERT(varchar(128), SUSER_NAME()) AS [VALUE]".
"UNION ALL ".
"SELECT 'USER_NAME' AS [NAME], CONVERT(varchar(128), USER_NAME()) AS [VALUE]".
"UNION ALL ".
"SELECT 'USER_ID' AS [NAME], CONVERT(varchar(128), USER_ID()) AS [VALUE]";
$stmt = sqlsrv_query($conn, $sql);
if( $stmt === false ) {
echo "Error (sqlsrv_query): ".print_r(sqlsrv_errors(), true);
exit;
}
while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
echo $row['NAME'].": ".$row['VALUE']."</br>";
}
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
?>
有关详细信息,请查看here。