PHP致命错误:调用未定义函数mssql_query() [英] PHP Fatal error: Call to undefined function mssql_query()
问题描述
所以当我想向ms sql服务器查询内容时,我总是收到此错误.
So I keep getting this error when I want to query something to the ms sql server..
已与数据库建立连接,但查询似乎失败.
The connection is made with the database but the queries seem to fail.
错误日志包含以下内容:
The error log contains this:
PHP Fatal error: Call to undefined function mssql_query()
php上的代码:
session_start();
include_once("connect.php");
if (isset($_POST['username'])) {
$username = $_POST['username'];
$password = $_POST['password'];
$sql = "SELECT * FROM test WHERE username='".$username."' AND password='".$password."'";
$res = mssql_query ($sql) or die(mssql_error());
if (mssql_num_rows($res) == 1) {
$row = mssql_fetch_assoc($res);
$_SESSION['uid'] = $row['id'];
$_SESSION['username'] = $row['Username'];
$_SESSION['afdeling'] = $row['Afdeling'];
$_SESSION['mail'] = $row['Mail'];
header("Location: test.php");
exit();
} else {
echo "Invalid login information. Please return to the previous page.";
exit(); } } ?>
有人知道是什么问题吗?
Does anybody knows what the problem is?
提前谢谢!
connect.php代码:
connect.php code:
<?php
$serverName = "MTN-TEST"; //serverName\instanceName
$connectionInfo = array( "Database"=>"PROCES_TEST", "UID"=>"blaaa", "PWD"=>"blooo");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
echo "<span style='color:green;'>Connection established.</span><br />";
}else{
echo "<span style='color:red;'>Connection could not be established.</span><br />";
die( print_r( sqlsrv_errors(), true));
}
?>
推荐答案
您没有安装MS SQL驱动程序.
您可以使用phpinfo();
You don't have the MS SQL Drivers installed.
You can check this with phpinfo();
在 Linux 上,您需要mssql.so或sybase.so
使用debian,它的apt-get install php5-sybase
On Linux you need mssql.so or sybase.so
With debian its apt-get install php5-sybase
对于 windows ,请点击此处: http://msdn.microsoft.com/zh-CN/library/cc793139%28v = SQL.90%29.aspx
For windows take a look here: http://msdn.microsoft.com/en-US/library/cc793139%28v=SQL.90%29.aspx
需要为PHP配置驱动程序以找到函数mssql _...
Drivers need to be configured for PHP to find the function mssql_...
您还可以查看PDO DB类,因为它们可以连接到任何DBS,您需要安装驱动程序.
You could also look at PDO DB classes as they can connect to any DBS, you need the drivers installed tho.
这篇关于PHP致命错误:调用未定义函数mssql_query()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!