1--TEST--
2MySQL PDO->__construct(), libmysql only options
3--SKIPIF--
4<?php
5require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'skipif.inc');
6require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
7MySQLPDOTest::skip();
8if (MySQLPDOTest::isPDOMySQLnd())
9	die("skip libmysql only options")
10?>
11--FILE--
12<?php
13	require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
14
15	function set_option_and_check($offset, $option, $value, $option_desc, $ignore_diff = false) {
16
17		$dsn = MySQLPDOTest::getDSN();
18		$user = PDO_MYSQL_TEST_USER;
19		$pass = PDO_MYSQL_TEST_PASS;
20
21		try {
22			$db = new PDO($dsn, $user, $pass, array($option => $value));
23			if (!is_object($db) || (!$ignore_diff && ($value !== ($tmp = @$db->getAttribute($option)))))
24				printf("[%03d] Execting '%s'/%s got '%s'/%s' for options '%s'\n",
25					$offset,
26					$value, gettype($value),
27					$tmp, gettype($tmp),
28					$option_desc);
29		} catch (PDOException $e) {
30			printf("[%03d] %s\n", $offset, $e->getMessage());
31		}
32
33	}
34
35	try {
36
37		$dsn = MySQLPDOTest::getDSN();
38		$user = PDO_MYSQL_TEST_USER;
39		$pass = PDO_MYSQL_TEST_PASS;
40
41		$valid_options = array();
42		$valid_options[PDO::MYSQL_ATTR_MAX_BUFFER_SIZE] = 'PDO::MYSQL_ATTR_MAX_BUFFER_SIZE';
43		$valid_options[PDO::MYSQL_ATTR_INIT_COMMAND] = 'PDO::MYSQL_ATTR_INIT_COMMAND';
44		$valid_options[PDO::MYSQL_ATTR_READ_DEFAULT_FILE] = 'PDO::MYSQL_ATTR_READ_DEFAULT_FILE';
45		$valid_options[PDO::MYSQL_ATTR_READ_DEFAULT_GROUP] = 'PDO::MYSQL_ATTR_READ_DEFAULT_GROUP';
46
47		$defaults[PDO::MYSQL_ATTR_MAX_BUFFER_SIZE] = 1048576;
48		/* TODO getAttribute() does not handle it */
49		$defaults[PDO::MYSQL_ATTR_INIT_COMMAND] = '';
50		$defaults[PDO::MYSQL_ATTR_READ_DEFAULT_FILE] = false;
51		$defaults[PDO::MYSQL_ATTR_READ_DEFAULT_GROUP] = false;
52
53		$db = new PDO($dsn, $user, $pass);
54		foreach ($valid_options as $option => $name) {
55			/* TODO getAttribute() is pretty poor in supporting the options, suppress errors */
56			$tmp = @$db->getAttribute($option);
57			if ($tmp !== $defaults[$option])
58				printf("[001] Expecting default value for '%s' of '%s'/%s, getAttribute() reports setting '%s'/%s\n",
59					$name, $defaults[$option], gettype($defaults[$option]),
60					$tmp, gettype($tmp));
61		}
62
63		set_option_and_check(26, PDO::MYSQL_ATTR_READ_DEFAULT_FILE, true, 'PDO::MYSQL_ATTR_READ_DEFAULT_FILE');
64		set_option_and_check(27, PDO::MYSQL_ATTR_READ_DEFAULT_FILE, false, 'PDO::MYSQL_ATTR_READ_DEFAULT_FILE');
65
66		set_option_and_check(30, PDO::MYSQL_ATTR_MAX_BUFFER_SIZE, -1, 'PDO::MYSQL_ATTR_MAX_BUFFER_SIZE', true);
67		set_option_and_check(31, PDO::MYSQL_ATTR_MAX_BUFFER_SIZE, PHP_INT_MAX, 'PDO::MYSQL_ATTR_MAX_BUFFER_SIZE');
68		set_option_and_check(32, PDO::MYSQL_ATTR_MAX_BUFFER_SIZE, 1, 'PDO::MYSQL_ATTR_MAX_BUFFER_SIZE');
69
70
71	} catch (PDOException $e) {
72		printf("[001] %s, [%s] %s\n",
73			$e->getMessage(),
74			(is_object($db)) ? $db->errorCode() : 'n/a',
75			(is_object($db)) ? implode(' ', $db->errorInfo()) : 'n/a');
76	}
77
78	print "done!";
79?>
80--EXPECTF--
81[001] Expecting default value for 'PDO::MYSQL_ATTR_INIT_COMMAND' of ''/string, getAttribute() reports setting ''/boolean
82[026] Execting '1'/boolean got ''/boolean' for options 'PDO::MYSQL_ATTR_READ_DEFAULT_FILE'
83done!
84