Jump to content

PHP Version 5.4.0 and MSSQL


dieterm

Recommended Posts

HI,

 

I've upgraded from PHP version 5.2 to PHP version 5.4 and are not able to load / find mssql extension ?

 

How do I use MSSQL in version 5.4 ??

 

Is MSSQL not supported in this version or am I (hopingly) missing something ???

 

Regards

Dieter

Link to comment
Share on other sites

The mssql_* set of functions are not supported since 5.3.  The preferred extensions to use now are SQLSRV (on windows) and ODBC (on linux).

 

If your code uses the mssql_* functions you will either have to re-write the code to use the new drivers, downgrade back to php 5.2, or scour the web and see if you can find a third-party dll to enable the extension.

Link to comment
Share on other sites

Not sure if a find and replace would work.  I use the PDO api in my application rather than the function based api.

 

You could create an include file of wrapper functions to re-define the mssql_* functions, I did something like that in my code as a quick-fix to get some third-party code working until it could be re-written.

 

For example:

if (!function_exists('mssql_query')){
   include 'mssql_compat.inc.php';
}

 

mssql_compat.inc.php - keep in mind this is using pdo as a base, your implementations would differ.

<?php

/**
* mssql_query replacement.
* 
* Provides a wrapper for mssql_query
*
* @param string $sql The query to execute.
* @param PDO $link The connection to query on.  Defaults to the currently active connection.
* @return PDOStatement
*/
function mssql_query($sql, $link=null){
if (!$link) $link=DB::GetFromPool();

$stmt = $link->prepare($sql);
if (!$stmt){
	throw new SQLException($link, $sql);
}

if (!$stmt->execute()){
	throw new DatabaseException($link, $stmt, $sql);
}

$stmt->_rows = $stmt->fetchAll();
reset($stmt->_rows);

return $stmt;
}

/**
* mssql_fetch_array replacement.
*
* Provides a wrapper for mssql_fetch_array
*
* @param PDOStatement $stmt The result set.
* @param int $type The type of results to fetch, should be one of the PDO class constants.
* @return mixed
*/
function mssql_fetch_array($stmt, $type=PDO::FETCH_BOTH){
if (!($stmt instanceof PDOStatement)){
	throw new InvalidArgumentException('$stmt must be a PDOStatement object');
}

if (is_array($stmt->_rows)){
	$row=current($stmt->_rows);
	next($stmt->_rows);

	if ($type == PDO::FETCH_BOTH || !is_array($row)){
		return $row;
	}
	else {
		$ret=array();
		foreach ($row as $k=>$v){
			if ($type == PDO::FETCH_ASSOC && !is_int($k)){
				$ret[$k] = $v;
			}
			else if ($type == PDO::FETCH_NUM && is_int($k)){
				$ret[$k] = $v;
			}
		}
		return $ret;
	}
}
else {
	return false;
}
}

///more functions

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.