PHP Fatal Error: Call to Undefined Function Mssql_Query()

PHP Fatal error: Call to undefined function mssql_query()

You don't have the MS SQL Drivers installed.
You can check this with phpinfo();

On Linux you need mssql.so or sybase.so
With debian its apt-get install php5-sybase

For windows take a look here:
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_...

You could also look at PDO DB classes as they can connect to any DBS, you need the drivers installed tho.

PHP Fatal error: Call to undefined function mssql_select_db() in c:\...appscript.php on line 16

It seems you are using wrong functions. You should use only functions from http://www.php.net/manual/en/function.sqlsrv-begin-transaction.php

It seems there is no need to select db (there is no sqlserv_select_db function).

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.

Fatal error: Call to undefined function mssql_connect() in C:\AppServ\Apache24\htdocs\C_DBHandler.inc using apache 2.4 and php5.6

Changes, that have to be made, to migrate from MSSQL to SQLSRV extensions of PHP:

Connection:

Functions mssql_connect() and mssql_select_db() must be replaced with sqlsrv_connect():

public 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 = sqlsrv_connect($this->db_Host, array("Database"=>$this->db_Database, "UID"=>$this->db_User, "PWD"=>$this->db_Password));
if ($this->db_Link === false) {
$Err->SendAdminInfo("mail_db");
die("<br><br><b><font color=\"red\">Invalid SQL connect-DB</font></b>");
exit;
}
}
}

Query:

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

Fetch record:

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

Row count:

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];
}

Notes:

You can read Brian Swan's article and Microsoft documentation.

Fatal error: Call to a member function query() on a non-object XAMPP to SQL SERVER 2012

Functions sqlsrv_* are part of PHP Driver for SQL Server and they are not object oriented. This is the reason for your error.

Your conn.php seems correct, so just use appropriate sqlsrv_* functions in login.php:

<?
session_start();
include 'includes/conn.php';

if (isset($_POST['login'])) {
$username = $_POST['username'];
$password = $_POST['password'];
$sql = "SELECT * FROM usermasterfile WHERE username = '$username'";
$query = sqlsrv_query($conn, $sql, array(), array("Scrollable" => SQLSRV_CURSOR_KEYSET));
if ($query === false ) {
echo "Error (sqlsrv_query): ".print_r(sqlsrv_errors(), true);
exit;
}

if (sqlsrv_num_rows($query) < 1) {
$_SESSION['error'] = 'Cannot find account with the username';
} else {
$row = sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC);
if (password_verify($password, $row['password'])) {
$_SESSION['admin'] = $row['id'];
}
else{
$_SESSION['error'] = 'Incorrect password';
}
}
}
else{
$_SESSION['error'] = 'Input admin credentials first';
}

header('location: index.php');
?>


Related Topics



Leave a reply



Submit