简体   繁体   English

PHP 致命错误:调用未定义的函数 mssql_query()

[英]PHP Fatal error: Call to undefined function mssql_query()

So I keep getting this error when I want to query something to the ms sql server..因此,当我想向 ms sql 服务器查询某些内容时,我不断收到此错误..

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()

The code on the php: 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?有谁知道问题是什么?

Thanks in advance!提前致谢!

connect.php code: connect.php 代码:

<?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));
}
?>

You don't have the MS SQL Drivers installed.您没有安装 MS SQL 驱动程序。 You can check this with phpinfo();你可以用phpinfo();来检查这个phpinfo();

On Linux you need mssql.so or sybase.so With debian its apt-get install php5-sybaseLinux 上,您需要 mssql.so 或 sybase.so 使用 debian 它的apt-get install php5-sybase

For windows take a look here: http://msdn.microsoft.com/en-US/library/cc793139%28v=SQL.90%29.aspx对于Windows,请查看此处: http : //msdn.microsoft.com/en-US/library/cc793139%28v=SQL.90%29.aspx

Drivers need to be configured for PHP to find the function mssql_...需要为 PHP 配置驱动程序才能找到函数 mssql_...

You could also look at PDO DB classes as they can connect to any DBS, you need the drivers installed tho.您还可以查看 PDO DB 类,因为它们可以连接到任何 DBS,您需要安装驱动程序。

If your connect.php code returns "Connection established.", it's mean you installed MS SQL Drivers correctly.如果您的 connect.php 代码返回“已建立连接。”,则表示您正确安装了 MS SQL 驱动程序。 You have to use sqlsrv_query function instead of mssql_query .您必须使用sqlsrv_query函数而不是mssql_query The correct form of this command is:此命令的正确形式是:

     <?php
                $serverName = "serverName"; 
                $options = array(  "UID" => "sa",  "PWD" => "Password",  "Database" => "DBname");
                $conn = sqlsrv_connect($serverName, $options);

                if( $conn ) {
                     echo "Connection established.<br />";

                     $query='select * from test';
                     $result = sqlsrv_query($conn,$query);

                }else{
                     echo "Connection could not be established.<br />";
                     die( print_r( sqlsrv_errors(), true));
                }

            ?>

you can learn more here:你可以在这里了解更多:

"PHP Fatal error: Call to undefined function mssql_select_db() in c:\\...appscript.php on line 16" “PHP 致命错误:在第 16 行调用 c:\\...appscript.php 中未定义的函数 mssql_select_db()”

您可以将mssql_get_last_message()用于 mssql 错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM