dieterm Posted April 20, 2012 Share Posted April 20, 2012 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 https://forums.phpfreaks.com/topic/261292-php-version-540-and-mssql/ Share on other sites More sharing options...
kicken Posted April 20, 2012 Share Posted April 20, 2012 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 https://forums.phpfreaks.com/topic/261292-php-version-540-and-mssql/#findComment-1338991 Share on other sites More sharing options...
dieterm Posted April 20, 2012 Author Share Posted April 20, 2012 Thanks, So I need to change all MSSQL functions in my project to SQLSRV ??? Do you think I can just do a find and replace of MSSQL to SQLSRV ? Link to comment https://forums.phpfreaks.com/topic/261292-php-version-540-and-mssql/#findComment-1338997 Share on other sites More sharing options...
kicken Posted April 20, 2012 Share Posted April 20, 2012 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 https://forums.phpfreaks.com/topic/261292-php-version-540-and-mssql/#findComment-1339030 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.