1--TEST-- 2PDO_DBLIB: Column data types, with or without stringifying 3--EXTENSIONS-- 4pdo_dblib 5--SKIPIF-- 6<?php 7require __DIR__ . '/config.inc'; 8getDbConnection(); 9?> 10--FILE-- 11<?php 12require __DIR__ . '/config.inc'; 13 14$db = getDbConnection(); 15 16function get_expected_float_string() { 17 global $db; 18 19 switch ($db->getAttribute(PDO::DBLIB_ATTR_TDS_VERSION)) { 20 case '5.0': 21 case '6.0': 22 case '7.0': 23 case '7.1': 24 case '7.2': 25 case '8.0': 26 return '10.500'; 27 default: 28 return '10.5'; 29 } 30} 31 32$sql = " 33 SELECT 34 'foo' AS [char], 35 CAST('2030-01-01 23:59:59' AS DATETIME) AS [datetime], 36 CAST(0 AS BIT) AS [false], 37 10.500 AS [float], 38 1000 AS [int], 39 CAST(10.500 AS MONEY) AS [money], 40 CAST('1950-01-18 23:00:00' AS SMALLDATETIME) as [smalldatetime], 41 CAST(1 AS BIT) AS [true] 42"; 43 44$stmt = $db->query($sql); 45$row = $stmt->fetch(PDO::FETCH_ASSOC); 46 47var_dump($row['char']); 48var_dump($row['datetime']); 49var_dump($row['false']); 50var_dump($row['float']); 51var_dump($row['int']); 52var_dump($row['money']); 53var_dump($row['smalldatetime']); 54var_dump($row['true']); 55 56$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); 57$stmt = $db->query($sql); 58$row = $stmt->fetch(PDO::FETCH_ASSOC); 59 60var_dump($row['char']); 61var_dump($row['datetime']); 62var_dump($row['false']); 63var_dump($row['float'] === get_expected_float_string()); 64var_dump($row['int']); 65// var_dump($row['money']); -- the decimal precision varies and it's not clear why 66var_dump($row['smalldatetime']); 67var_dump($row['true']); 68 69?> 70--EXPECT-- 71string(3) "foo" 72string(19) "2030-01-01 23:59:59" 73int(0) 74float(10.5) 75int(1000) 76float(10.5) 77string(19) "1950-01-18 23:00:00" 78int(1) 79string(3) "foo" 80string(19) "2030-01-01 23:59:59" 81string(1) "0" 82bool(true) 83string(4) "1000" 84string(19) "1950-01-18 23:00:00" 85string(1) "1" 86