致命错误:使用apache 2.4和php5.6调用C:\AppServ\Apache24\htdocs\C_DBHandler.inc中未定义的函数mssql_connect()

致命错误:使用apache 2.4和php5.6调用C:\AppServ\Apache24\htdocs\C_DBHandler.inc中未定义的函数mssql_connect(),php,sql-server,apache,sqlsrv,php-mssql,Php,Sql Server,Apache,Sqlsrv,Php Mssql,我也从PHP2.2升级到2.4和PHP5.6。问题在于新的php函数不支持mssql_connect,因此我安装了新的sqlsvr驱动程序,当我建立数据库连接时,它工作正常 我需要一些帮助。如何将此代码从mssql更改为sqlsvr谢谢您和我等待您的回答 <?php class C_DBHandler { private $db_Host = ""; // Host, auf dem die DB läuft private $db_Database =

我也从PHP2.2升级到2.4和PHP5.6。问题在于新的php函数不支持mssql_connect,因此我安装了新的sqlsvr驱动程序,当我建立数据库连接时,它工作正常

我需要一些帮助。如何将此代码从mssql更改为sqlsvr谢谢您和我等待您的回答

<?php

class C_DBHandler 
{

 private $db_Host     = "";         // Host, auf dem die DB läuft
 private $db_Database = "";         // zu verwendetende Database
 private $db_User     = "";         // User und Paßwort für Login
 private $db_Password = "";

 private $db_Link     = 0;          // Resultat des connect()
 private $db_Query    = 0;          // Resultat des query()
 private $db_Record   = array();    // aktuelles fetch_array()-Ergebnis
 private $db_Row;                   // Aktuelle Ergebniszeile
 private $db_numRows = "";

 private $LSDconf     = "";
 private $LSDDBconf   = "";
 private static $instance;          // Klasseninstanzname



public function __get($property){
    $Err = C_GetHDL();
    $Err->SetSubject("LSD-Error (property)");
    $Err->SetBody("Attempt to read from not existing property \"$property\". Class: \"".__CLASS__."\"; Triggered by User: \"".$_SESSION['ULogin']."\"");
    $Err->SendAdminInfo("mail_db");
}

public function __set($property, $val){
    $Err = C_FuncHandler::GetHDL();
    $Err->SetSubject("LSD-Error (property)");
    $Err->SetBody("Attempt to write \"$val\" to not existing property \"$property\". Class: \"".__CLASS__."\"; Triggered by User: \"".$_SESSION['ULogin']."\"");
    $Err->SendAdminInfo("mail_db");
}

function __autoload($className){
    $fileName = $className.'.inc';
    require($fileName);
}




private function __construct(){
    require ('config.inc');
    require ('DB-config.inc');
    $this->LSDconf   = $LSDconf;
    $this->LSDDBconf = $LSDDBconf;
}


public function __clone()
{
   trigger_error('Clone is not allowed.', E_USER_ERROR);
}



public static function GetHDL()
{
   if (!isset(self::$instance)) {
       $c = __CLASS__;
       self::$instance = new $c;
   }

   return self::$instance;
}


 private function connect() {
    $this->db_Host      = $this->LSDDBconf['DBSec']['host'];
    $this->db_Database  = $this->LSDDBconf['DBSec']['dbname'];
    $this->db_Password  = $this->LSDDBconf['DBSec']['pwd'];
    $this->db_User      = $this->LSDDBconf['DBSec']['user'];

    if ( 0 == $this->db_Link ) {
        $this->db_Link=mssql_connect($this->db_Host, $this->db_User, $this->db_Password);
        if (!$this->db_Link) {
            die("<br><br><b><font color=\"red\">Invalid SQL connect-DB</font></b>");

        }
        if (!mssql_select_db($this->db_Database,$this->db_Link)) {              $Err->SendAdminInfo("mail_db");
            die("<br><br><b><font color=\"red\">Invalid SQL select-DB</font></b>");

        }
    }
 }


 public function query($Query_String) {
    $this->connect();
    $this->db_Query = mssql_query($Query_String,$this->db_Link);
    $this->db_Row   = 0;
    if (!$this->db_Query) {
        die("<br><br><b><font color=\"red\">Invalid SQL Query</font></b>");

    }
    return $this->db_Query;
 }


 public function next_record() {
    $this->db_Record = mssql_fetch_array($this->db_Query);
    $this->db_Row   += 1;

    return $this->db_Record;
 }

 public function num_rows(){
    $this->db_numRows = mssql_num_rows($this->db_Query);
    return $this->db_numRows;
 }



 public function rows_affected(){
    $this->db_Query   = mssql_query("SELECT @@ROWCOUNT", $this->db_Link);
    $this->db_numRows = mssql_fetch_row($this->db_Query);
    return $this->db_numRows[0];
 }


public function mssql_addslashes($MyString) {
    $MyString = str_replace("'", "''", $MyString);
    return $MyString;
}

public function Setdb_Query($val){
    $this->db_Query = $val;
}

public function Getdb_Query(){
    return $this->db_Query;
}

   }
?>

如果安装了新库,您可能希望将
mssql\u connect()
替换为
sqlsrv\u connect()
。实际上,所有mssql函数都可以被替换。 这是第一个快速的想法:-)
顺便说一句:
mssql_connect()
仅从PHP7中删除,到目前为止,应在PHP5.6中使用:

必须进行更改,以便从mssql迁移到php的SQLSRV扩展:

连接:

public function query($Query_String) {
    $this->connect();
    # SQLSRV_CURSOR_FORWARD - Lets you move one row at a time starting at the first row of the result set until you reach the end of the result set.
    # This is the default cursor type. sqlsrv_num_rows returns an error for result sets created with this cursor type.
    # SQLSRV_CURSOR_STATIC - Lets you access rows in any order but will not reflect changes in the database.
    # SQLSRV_CURSOR_DYNAMIC - Lets you access rows in any order and will reflect changes in the database. 
    # sqlsrv_num_rows returns an error for result sets created with this cursor type.
    # SQLSRV_CURSOR_KEYSET - Lets you access rows in any order. However, a keyset cursor does not update the row count if a row is deleted from the
    # table (a deleted row is returned with no values).
    # SQLSRV_CURSOR_CLIENT_BUFFERED - Lets you access rows in any order. Creates a client-side cursor query.
    $this->db_Query = sqlsrv_query($this->db_Link, $Query_String, array(), array("Scrollable" => SQLSRV_CURSOR_KEYSET));
    $this->db_Row   = 0;
    if (!$this->db_Query) {
        die("<br><br><b><font color=\"red\">Invalid SQL Query</font></b>");
    }
    return $this->db_Query;
}
public function next_record() {
    # SQLSRV_FETCH_ASSOC - sqlsrv_fetch_array returns the next row of data as anassociative array.
    # SQLSRV_FETCH_BOTH - sqlsrv_fetch_array returns the next row of data as an array with both numeric and associative keys. This is the default value.
    # SQLSRV_FETCH_NUMERIC - sqlsrv_fetch_array returns the next row of data as a numerically indexed array
    $this->db_Record = sqlsrv_fetch_array($this->db_Query, SQLSRV_FETCH_BOTH);
    $this->db_Row   += 1;
    return $this->db_Record;
}
public function num_rows(){
    # sqlsrv_num_rows requires a client-side, static, or keyset cursor, and will return false if you use a forward cursor or
    # a dynamic cursor. (A forward cursor is the default.) For more information about cursors, see sqlsrv_query and Cursor Types (SQLSRV Driver).
    $this->db_numRows = sqlsrv_num_rows($this->db_Query);
    return $this->db_numRows;
}
public function rows_affected(){
    $this->db_Query   = sqlsrv_query($this->db_Link, "SELECT @@ROWCOUNT");
    $this->db_numRows = sqlsrv_fetch_array($this->db_Query, SQLSRV_FETCH_NUMERIC);
    return $this->db_numRows[0];
}
函数
mssql\u connect()
mssql\u select\u db()
必须替换为
sqlsrv\u connect()

行计数:

public function query($Query_String) {
    $this->connect();
    # SQLSRV_CURSOR_FORWARD - Lets you move one row at a time starting at the first row of the result set until you reach the end of the result set.
    # This is the default cursor type. sqlsrv_num_rows returns an error for result sets created with this cursor type.
    # SQLSRV_CURSOR_STATIC - Lets you access rows in any order but will not reflect changes in the database.
    # SQLSRV_CURSOR_DYNAMIC - Lets you access rows in any order and will reflect changes in the database. 
    # sqlsrv_num_rows returns an error for result sets created with this cursor type.
    # SQLSRV_CURSOR_KEYSET - Lets you access rows in any order. However, a keyset cursor does not update the row count if a row is deleted from the
    # table (a deleted row is returned with no values).
    # SQLSRV_CURSOR_CLIENT_BUFFERED - Lets you access rows in any order. Creates a client-side cursor query.
    $this->db_Query = sqlsrv_query($this->db_Link, $Query_String, array(), array("Scrollable" => SQLSRV_CURSOR_KEYSET));
    $this->db_Row   = 0;
    if (!$this->db_Query) {
        die("<br><br><b><font color=\"red\">Invalid SQL Query</font></b>");
    }
    return $this->db_Query;
}
public function next_record() {
    # SQLSRV_FETCH_ASSOC - sqlsrv_fetch_array returns the next row of data as anassociative array.
    # SQLSRV_FETCH_BOTH - sqlsrv_fetch_array returns the next row of data as an array with both numeric and associative keys. This is the default value.
    # SQLSRV_FETCH_NUMERIC - sqlsrv_fetch_array returns the next row of data as a numerically indexed array
    $this->db_Record = sqlsrv_fetch_array($this->db_Query, SQLSRV_FETCH_BOTH);
    $this->db_Row   += 1;
    return $this->db_Record;
}
public function num_rows(){
    # sqlsrv_num_rows requires a client-side, static, or keyset cursor, and will return false if you use a forward cursor or
    # a dynamic cursor. (A forward cursor is the default.) For more information about cursors, see sqlsrv_query and Cursor Types (SQLSRV Driver).
    $this->db_numRows = sqlsrv_num_rows($this->db_Query);
    return $this->db_numRows;
}
public function rows_affected(){
    $this->db_Query   = sqlsrv_query($this->db_Link, "SELECT @@ROWCOUNT");
    $this->db_numRows = sqlsrv_fetch_array($this->db_Query, SQLSRV_FETCH_NUMERIC);
    return $this->db_numRows[0];
}
注意事项:

public function query($Query_String) {
    $this->connect();
    # SQLSRV_CURSOR_FORWARD - Lets you move one row at a time starting at the first row of the result set until you reach the end of the result set.
    # This is the default cursor type. sqlsrv_num_rows returns an error for result sets created with this cursor type.
    # SQLSRV_CURSOR_STATIC - Lets you access rows in any order but will not reflect changes in the database.
    # SQLSRV_CURSOR_DYNAMIC - Lets you access rows in any order and will reflect changes in the database. 
    # sqlsrv_num_rows returns an error for result sets created with this cursor type.
    # SQLSRV_CURSOR_KEYSET - Lets you access rows in any order. However, a keyset cursor does not update the row count if a row is deleted from the
    # table (a deleted row is returned with no values).
    # SQLSRV_CURSOR_CLIENT_BUFFERED - Lets you access rows in any order. Creates a client-side cursor query.
    $this->db_Query = sqlsrv_query($this->db_Link, $Query_String, array(), array("Scrollable" => SQLSRV_CURSOR_KEYSET));
    $this->db_Row   = 0;
    if (!$this->db_Query) {
        die("<br><br><b><font color=\"red\">Invalid SQL Query</font></b>");
    }
    return $this->db_Query;
}
public function next_record() {
    # SQLSRV_FETCH_ASSOC - sqlsrv_fetch_array returns the next row of data as anassociative array.
    # SQLSRV_FETCH_BOTH - sqlsrv_fetch_array returns the next row of data as an array with both numeric and associative keys. This is the default value.
    # SQLSRV_FETCH_NUMERIC - sqlsrv_fetch_array returns the next row of data as a numerically indexed array
    $this->db_Record = sqlsrv_fetch_array($this->db_Query, SQLSRV_FETCH_BOTH);
    $this->db_Row   += 1;
    return $this->db_Record;
}
public function num_rows(){
    # sqlsrv_num_rows requires a client-side, static, or keyset cursor, and will return false if you use a forward cursor or
    # a dynamic cursor. (A forward cursor is the default.) For more information about cursors, see sqlsrv_query and Cursor Types (SQLSRV Driver).
    $this->db_numRows = sqlsrv_num_rows($this->db_Query);
    return $this->db_numRows;
}
public function rows_affected(){
    $this->db_Query   = sqlsrv_query($this->db_Link, "SELECT @@ROWCOUNT");
    $this->db_numRows = sqlsrv_fetch_array($this->db_Query, SQLSRV_FETCH_NUMERIC);
    return $this->db_numRows[0];
}

如果我试图连接到数据库,你需要安装mssql模块(可能还有大量的支持库,如FreeTDS),如果我遇到同样的错误,在php.ini中,我添加了所有的ext,我得到了相同的错误。谢谢你的回答和漂亮的链接,我喜欢这里的链接,我修改了$this->db\u Link=sqlsrv\u connect的代码($this->db\u Database,$this->db\u Host,$this->db\u User,$this->db\u密码);sqlsrv_connect($this->db_数据库,$this->db_链接);我得到以下错误:可捕获致命错误:传递给sqlsrv_connect()的参数2必须是数组类型,字符串为,在第147行的C:\AppServ\Apache24\htdocs\C_DBHandler.inc中调用,并在第132行的C:\AppServ\Apache24\htdocs\C_DBHandler.inc中定义。我不知道可能缺少$Servername数组function@klk2000函数mssql_connect()和mssql_select_db()必须仅替换为一个具有以下语法的函数sqlsrv_connect():sqlsrv_connect($this->db\u Host,$conninfo)。使用sqlsrv\u connect($this->db\u Database,$this->db\u Host,$this->db\u User,$this->db\u Password);这种方式是不正确的。感谢您的帮助,连接到数据库工作正常,但我在用户身份验证方面遇到问题,他们无法登录,可能我在这里遗漏了什么: