1--TEST-- 2MySQL PDO->getAttribute() 3--EXTENSIONS-- 4pdo_mysql 5--SKIPIF-- 6<?php 7require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); 8MySQLPDOTest::skip(); 9$db = MySQLPDOTest::factory(); 10if (false == MySQLPDOTest::detect_transactional_mysql_engine($db)) 11 die("skip Transactional engine not found"); 12?> 13--FILE-- 14<?php 15 require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); 16 $db = MySQLPDOTest::factory(); 17 MySQLPDOTest::createTestTable($db, MySQLPDOTest::detect_transactional_mysql_engine($db)); 18 19 function set_and_get($offset, $db, $attribute, $value) { 20 21 $value_type = gettype($value); 22 try { 23 24 if (!$db->setAttribute($attribute, $value)) { 25 printf("[%03d] Cannot set attribute '%s' to value '%s'\n", 26 $offset, $attribute, var_export($tmp, true)); 27 return false; 28 } 29 30 if (gettype($value) != $value_type) { 31 printf("[%03d] Call to PDO::setAttribute(int attribute, mixed value) has changed the type of value from %s to %s, test will not work properly\n", 32 $offset, $value_type, gettype($value)); 33 return false; 34 } 35 36 $tmp = $db->getAttribute($attribute); 37 if ($tmp !== $value) { 38 printf("[%03d] Attribute '%s' was set to '%s'/%s but getAttribute() reports '%s'/%s\n", 39 $offset, $attribute, var_export($value, true), gettype($value), var_export($tmp, true), gettype($tmp)); 40 return false; 41 } 42 43 } catch (PDOException $e) { 44 printf("[%03d] %s, [%s] %s\n", 45 $offset, $e->getMessage(), 46 $db->errorCode(), implode(' ', $db->errorInfo())); 47 return false; 48 } 49 50 return true; 51 } 52 53 set_and_get(1, $db, PDO::ATTR_AUTOCOMMIT, 1); 54/* 55 set_and_get(2, $db, PDO::ATTR_AUTOCOMMIT, 0); 56 set_and_get(3, $db, PDO::ATTR_AUTOCOMMIT, -1); 57 $obj = new stdClass(); 58 set_and_get(4, $db, PDO::ATTR_AUTOCOMMIT, $obj); 59 60 set_and_get(5, $db, PDO::MYSQL_ATTR_LOCAL_INFILE, 1); 61 set_and_get(6, $db, PDO::MYSQL_ATTR_LOCAL_INFILE, 0); 62 set_and_get(7, $db, PDO::MYSQL_ATTR_LOCAL_INFILE, -1); 63 $tmp = array(); 64 set_and_get(8, $db, PDO::MYSQL_ATTR_LOCAL_INFILE, $tmp); 65 66 set_and_get(9, $db, PPDO::MYSQL_ATTR_INIT_COMMAND, ''); 67 set_and_get(10, $db, PPDO::MYSQL_ATTR_INIT_COMMAND, 'SOME SQL'); 68 set_and_get(11, $db, PPDO::MYSQL_ATTR_INIT_COMMAND, -1); 69 70*/ 71/* 72PDO::MYSQL_ATTR_READ_DEFAULT_FILE (integer) 73 74 Read options from the named option file instead of from my.cnf. 75PDO::MYSQL_ATTR_READ_DEFAULT_GROUP (integer) 76 77 Read options from the named group from my.cnf or the file specified with MYSQL_READ_DEFAULT_FILE. 78PDO::MYSQL_ATTR_MAX_BUFFER_SIZE (integer) 79 80 Maximum buffer size. Defaults to 1 MiB. 81PDO::MYSQL_ATTR_DIRECT_QUERY (integer) 82 83 Perform direct queries, don't use prepared statements. 84*/ 85/* 86TODO - read only 87PDO::ATTR_CONNECTION_STATUS 88PDO::ATTR_SERVER_INFO 89*/ 90 91 print "done!"; 92?> 93--CLEAN-- 94<?php 95require __DIR__ . '/mysql_pdo_test.inc'; 96MySQLPDOTest::dropTestTable(); 97?> 98--EXPECT-- 99done! 100