1--TEST-- 2MySQL PDO->__construct(), libmysql only options 3--SKIPIF-- 4<?php 5require_once(__DIR__ . DIRECTORY_SEPARATOR . 'skipif.inc'); 6require_once(__DIR__ . 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(__DIR__ . 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] Expecting '%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 echo "Failed to getAttribute() for $option_desc\n"; 31 } 32 } 33 34 $dsn = MySQLPDOTest::getDSN(); 35 $user = PDO_MYSQL_TEST_USER; 36 $pass = PDO_MYSQL_TEST_PASS; 37 38 $valid_options = array(); 39 $valid_options[PDO::MYSQL_ATTR_MAX_BUFFER_SIZE] = 'PDO::MYSQL_ATTR_MAX_BUFFER_SIZE'; 40 $valid_options[PDO::MYSQL_ATTR_INIT_COMMAND] = 'PDO::MYSQL_ATTR_INIT_COMMAND'; 41 $valid_options[PDO::MYSQL_ATTR_READ_DEFAULT_FILE] = 'PDO::MYSQL_ATTR_READ_DEFAULT_FILE'; 42 $valid_options[PDO::MYSQL_ATTR_READ_DEFAULT_GROUP] = 'PDO::MYSQL_ATTR_READ_DEFAULT_GROUP'; 43 44 $defaults[PDO::MYSQL_ATTR_MAX_BUFFER_SIZE] = 1048576; 45 /* TODO getAttribute() does not handle it */ 46 $defaults[PDO::MYSQL_ATTR_INIT_COMMAND] = ''; 47 $defaults[PDO::MYSQL_ATTR_READ_DEFAULT_FILE] = false; 48 $defaults[PDO::MYSQL_ATTR_READ_DEFAULT_GROUP] = false; 49 50 $db = new PDO($dsn, $user, $pass); 51 foreach ($valid_options as $option => $name) { 52 try { 53 $tmp = $db->getAttribute($option); 54 if ($tmp !== $defaults[$option]) 55 printf("[001] Expecting default value for '%s' of '%s'/%s, getAttribute() reports setting '%s'/%s\n", 56 $name, $defaults[$option], gettype($defaults[$option]), 57 $tmp, gettype($tmp)); 58 } catch (PDOException $e) { 59 echo "Failed to getAttribute() for $name\n"; 60 } 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 print "done!\n"; 71?> 72--EXPECT-- 73Failed to getAttribute() for PDO::MYSQL_ATTR_INIT_COMMAND 74Failed to getAttribute() for PDO::MYSQL_ATTR_READ_DEFAULT_FILE 75Failed to getAttribute() for PDO::MYSQL_ATTR_READ_DEFAULT_GROUP 76Failed to getAttribute() for PDO::MYSQL_ATTR_READ_DEFAULT_FILE 77Failed to getAttribute() for PDO::MYSQL_ATTR_READ_DEFAULT_FILE 78done! 79