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