PHP Fatal Error: Call to Undefined Function Mssql_Connect()

PHP Fatal error: Call to undefined function mssql_connect()

I have just tried to install that extension on my dev server.

First, make sure that the extension is correctly enabled. Your phpinfo() output doesn't seem complete.

If it is indeed installed properly, your phpinfo() should have a section that looks like this:
Sample Image

If you do not get that section in your phpinfo(). Make sure that you are using the right version. There are both non-thread-safe and thread-safe versions of the extension.

Finally, check your extension_dir setting. By default it's this: extension_dir = "ext", for most of the time it works fine, but if it doesn't try: extension_dir = "C:\PHP\ext".

===========================================================================

EDIT given new info:

You are using the wrong function. mssql_connect() is part of the Mssql extension. You are using microsoft's extension, so use sqlsrv_connect(), for the API for the microsoft driver, look at SQLSRV_Help.chm which should be extracted to your ext directory when you extracted the extension.

Xampp php 5.6 mssql_connect() Fatal error: Call to undefined function mssql_connect()

Explanations:

MSSQL extension (mssql_ functions) is not available anymore on Windows with PHP 5.3 or later.

Warning This feature was REMOVED in PHP 7.0.0.

Alternatives to this feature include: PDO_SQLSRV PDO_ODBC SQLSRV
Unified ODBC API These functions allow you to access MS SQL Server
database.

This extension is not available anymore on Windows with PHP 5.3 or
later.

Solution:

What you can do is to install PHP Driver for SQL Server. You need to download the appropriate version of this driver. For PHP 5.6 - version 3.2 (32-bit or 64-bit also depends on PHP version). Also download and install an appropriate ODBC driver.

Sample script:

<?php
$serverName = "server\instance,port";
$connectionInfo = array(
"UID" => "username",
"PWD" => "password",
"Database" => "database"
);
$conn = sqlsrv_connect($serverName, $connectionInfo);
if ($conn === false) {
echo "Unable to connect.</br>";
exit;
} else {
echo "Connected.</br>";
}

// Other code here ...

sqlsrv_close($conn);
?>

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.

Call to undefined .. mssql_connect when using PHP in IIS?

Look at this link:

  • PHP Fatal error: Call to undefined function mssql_connect()

1) Check your PHP.INI file's extension_dir

2) Make sure you copied your .dlls into that directory (for example, into C:\PHP\ext").

3) Create a dummy page to call phpinfo();. Display the page in a browser. Make sure you see entries for "sqlsrv".

'Hope that helps!

Fatal error: Call to undefined function mssql_connect() or sqlsrv_connect() in xampp

mssql_connect() is no longer supported by PHP since PHP 7.0 and was depreciated in 5.3.

Create a phpinfo.php file:

<?php

// Show all information, defaults to INFO_ALL
phpinfo();

?>

Open the page, and on the first page that's opened, third from the bottom, check if the registered streams contains 'sqlsrv':

Registered PHP Streams  php, file, glob, data, http, ftp, zip, compress.zlib, phar, sqlsrv

If it doesn't then you have to enable the module.
Try uncomment this code that you changed:
From:

; On windows: extension_dir = "D:\xampp\php\ext" "

To:

On windows: extension_dir = "D:\xampp\php\ext"

And let us know the outcome.

Issues with connecting Ubuntu 16.04 to MSSQL

The mssql_* family of functions have been deprecated for a very long time, and were finally removed in PHP 7.0.

You can switch to using PDO as suggested in another answer, or use the sqlsrv_* functions:

<?php
$params = [
"UID" => "<usrname>",
"PWD" => "<password>",
"Database" => "infobase",
];
$conn = sqlsrv_connect("BWSQL", $params);
$query_result = sqlsrv_query($conn, "SELECT * FROM dbo.Staff");
$row = sqlsrv_fetch_array($query_result);
echo "The field number one is: $row[0]";
sqlsrv_close($conn); // close connection

Call to undefined function mssql_connect()

Open php.ini ,just add this line

extension=php_sqlsrv_53_ts_vc9.dll

you need to know what compiler do you use

phpinfo();

Compiler MSVC9 (Visual C++ 2008)

Than Add it.



Related Topics



Leave a reply



Submit