How to replace non exsiting mssql_query and mssql_connection functions

If you moved your php application to version 7.0+ then your application may stop working if you are using MSSQL.

I have created the following library to fix my problem and replace the non-existing function with their replacement.

<?php
if (function_exists(‘mssql_connect’)){
}else{
require_once(“mssql_ovewrite.php”);
}
?>
mssql_overwrite.php
function mssql_connect($db_server, $db_user, $db_pass) {
global $link,$db_server,$db_user,$db_pass;
$connectionOptions = array(
“Database”=>”xx”,
“Uid”=> $db_user,
“PWD”=> $db_pass,
“TraceOn”=>”0”,
“CharacterSet”=>”UTF-8”,
“ConnectionPooling”=>”1”,
‘MultipleActiveResultSets’=>false
);
//Establishes the connection
$link = sqlsrv_connect($db_server, $connectionOptions);
if( $link ===false ) {
}else{
return $link;
}
}
function mssql_select_db($db_database, $link){
returntrue;
}
function mssql_query($query, $link = 0){
global $db_server,$db_user,$db_pass,$link;
if($link ==0){
$link = mssql_connect($db_server, $db_user, $db_pass);
}
$r = sqlsrv_query($link, $query,array(), array( “Scrollable” => ‘buffered’ ));
return $r;
}
function mssql_num_rows($r){
//return number of rows
returnsqlsrv_num_rows($r);
}
function mssql_fetch_object($r){
//return objects
returnsqlsrv_fetch_object($r);
}
function mssql_close(){
returntrue;
}
function mssql_fetch_array($r){
//return array
returnsqlsrv_fetch_array($r);
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.