I am upgrading a PHP application from an older 5.4 version to the latest 8.3.8 using PDO SQLSrv to connect to my database. I have a timestamp
data type in the database to check if a record has been modified prior to the user submitting their version of the data (preventing concurrent updates).
The below code when run on 5.4 will correctly return a string similar to 00000000009FA279
, however PHP 8.3.8 using the same settings returns a weird looking string A�
. Any help on resolving this is appreciated.
$db = new PDO("sqlsrv:Server=MyServer;Database=MyDatabase", 'MyUser', 'MyPassword', array(PDO::SQLSRV_ATTR_ENCODING => PDO::SQLSRV_ENCODING_SYSTEM));
$stmt = $db->prepare('SELECT [timestamp] FROM MyTable WHERE Id= 1');
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
print_r($row);
If I get the metadata for the column, PDO correctly says it is a timestamp
Array
(
[flags] => 0
[sqlsrv:decl_type] => timestamp
[native_type] => string
[table] =>
[pdo_type] => 2
[name] => timestamp
[len] => 8
[precision] => 0
)
For clarification, I am looking specifically at the SQL timestamp
data type and not a date/time timestamp.