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