Amit Dhamu

Software Engineer

Replacing MsSQL_ functions

Similar to the mysql_ functions being removed in PHP 7, mssql_ functions have too. Unfortunately, there is no "improved" extension for MSSQL.

Instead, we must use PDO.

- $conn = mssql_connect($server, $username, $password);
- mssql_select_db($db, $conn);
+ $conn = new PDO('dblib:host=$server;dbname=$db', $username, $password);

- mssql_query($sql, $conn)
+ $conn->query($sql)

- mssql_num_fields($result)
+ $result->columnCount()

- mssql_field_name($result, $offset)
+ $result->getColumnMeta($offset)

- mssql_num_rows($result)
+ $result->rowCount()

- mssql_fetch_row($result)
+ $result->fetch(PDO::FETCH_NUM)

- mssql_fetch_assoc($result)
+ $result->fetch(PDO::FETCH_ASSOC)

- mssql_fetch_object($result)
+ $result->fetch(PDO::FETCH_OBJ)

- mssql_get_last_message()
+ $conn->errorInfo()

 mssql / pdo

Migrating from mysql_ to mysqli_Valid PHP Types

Show Comments

Made with by Amit Dhamu.
© MMXX. All rights reserved.