xref: /PHP-7.0/ext/pdo_dblib/tests/types.phpt (revision 91c49c4a)
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	switch (get_tds_version()) {
14		case '5.0':
15		case '6.0':
16		case '7.0':
17		case '7.1':
18		case '7.2':
19		case '8.0':
20			return '10.500';
21		default:
22			return '10.5';
23	}
24}
25
26$sql = "
27	SELECT
28		'foo' AS [char],
29		CAST('2030-01-01 23:59:59' AS DATETIME) AS [datetime],
30		CAST(0 AS BIT) AS [false],
31		10.500 AS [float],
32		1000 AS [int],
33		CAST(10.500 AS MONEY) AS [money],
34		CAST('1950-01-18 23:00:00' AS SMALLDATETIME) as [smalldatetime],
35		CAST(1 AS BIT) AS [true]
36";
37
38$stmt = $db->query($sql);
39$row = $stmt->fetch(PDO::FETCH_ASSOC);
40
41var_dump($row['char'] === 'foo');
42var_dump($row['datetime'] === '2030-01-01 23:59:59');
43var_dump($row['false'] === 0);
44var_dump($row['float'] === 10.5);
45var_dump($row['int'] === 1000);
46var_dump($row['money'] === 10.5);
47var_dump($row['smalldatetime'] === '1950-01-18 23:00:00');
48var_dump($row['true'] === 1);
49
50$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
51$stmt = $db->query($sql);
52$row = $stmt->fetch(PDO::FETCH_ASSOC);
53
54var_dump($row['char'] === 'foo');
55var_dump($row['datetime'] === '2030-01-01 23:59:59');
56var_dump($row['false'] === '0');
57var_dump($row['float'] === get_expected_float_string());
58var_dump($row['int'] === '1000');
59var_dump($row['money'] === '10.50');
60var_dump($row['smalldatetime'] === '1950-01-18 23:00:00');
61var_dump($row['true'] === '1');
62
63?>
64--EXPECT--
65bool(true)
66bool(true)
67bool(true)
68bool(true)
69bool(true)
70bool(true)
71bool(true)
72bool(true)
73bool(true)
74bool(true)
75bool(true)
76bool(true)
77bool(true)
78bool(true)
79bool(true)
80bool(true)
81