1--TEST-- 2PDO MySQL specific class constants 3--SKIPIF-- 4<?php 5require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'skipif.inc'); 6if (!extension_loaded('mysqli') && !extension_loaded('mysqlnd')) { 7 /* Need connection to detect library version */ 8 require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); 9 MySQLPDOTest::skip(); 10} 11?> 12--FILE-- 13<?php 14 require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); 15 16 $expected = array( 17 'MYSQL_ATTR_USE_BUFFERED_QUERY' => true, 18 'MYSQL_ATTR_LOCAL_INFILE' => true, 19 'MYSQL_ATTR_DIRECT_QUERY' => true, 20 'MYSQL_ATTR_FOUND_ROWS' => true, 21 'MYSQL_ATTR_IGNORE_SPACE' => true, 22 'MYSQL_ATTR_INIT_COMMAND' => true, 23 "MYSQL_ATTR_SSL_KEY" => true, 24 "MYSQL_ATTR_SSL_CERT" => true, 25 "MYSQL_ATTR_SSL_CA" => true, 26 "MYSQL_ATTR_SSL_CAPATH" => true, 27 "MYSQL_ATTR_SSL_CIPHER" => true, 28 "MYSQL_ATTR_COMPRESS" => true, 29 "MYSQL_ATTR_MULTI_STATEMENTS" => true, 30 ); 31 32 if (!MySQLPDOTest::isPDOMySQLnd()) { 33 $expected['MYSQL_ATTR_MAX_BUFFER_SIZE'] = true; 34 $expected['MYSQL_ATTR_READ_DEFAULT_FILE'] = true; 35 $expected['MYSQL_ATTR_READ_DEFAULT_GROUP'] = true; 36 } 37 38 if (extension_loaded('mysqlnd')) { 39 $expected['MYSQL_ATTR_SERVER_PUBLIC_KEY'] = true; 40 } else if (extension_loaded('mysqli')) { 41 if (mysqli_get_client_version() > 50605) { 42 $expected['MYSQL_ATTR_SERVER_PUBLIC_KEY'] = true; 43 } 44 } else if (MySQLPDOTest::getClientVersion(MySQLPDOTest::factory()) > 50605) { 45 /* XXX the MySQL client library version isn't exposed with any 46 constants, the single possibility is to use the PDO::getAttribute(). 47 This however will fail with no connection. */ 48 $expected['MYSQL_ATTR_SERVER_PUBLIC_KEY'] = true; 49 } 50 51 /* 52 TODO 53 54 MYSQLI_OPT_CONNECT_TIMEOUT != PDO::ATTR_TIMEOUT (integer) 55 Sets the timeout value in seconds for communications with the database. 56 ^ Potential BUG, PDO::ATTR_TIMEOUT is used in pdo_mysql_handle_factory 57 58 MYSQLI_SET_CHARSET_NAME -> DSN/charset=<charset_name> 59 ^ Undocumented and pitfall for ext/mysqli users 60 61 Assorted mysqlnd settings missing 62 */ 63 $ref = new ReflectionClass('PDO'); 64 $constants = $ref->getConstants(); 65 $values = array(); 66 67 foreach ($constants as $name => $value) 68 if (substr($name, 0, 11) == 'MYSQL_ATTR_') { 69 if (!isset($values[$value])) 70 $values[$value] = array($name); 71 else 72 $values[$value][] = $name; 73 74 if (isset($expected[$name])) { 75 unset($expected[$name]); 76 unset($constants[$name]); 77 } 78 79 } else { 80 unset($constants[$name]); 81 } 82 83 if (!empty($constants)) { 84 printf("[001] Dumping list of unexpected constants\n"); 85 var_dump($constants); 86 } 87 88 if (!empty($expected)) { 89 printf("[002] Dumping list of missing constants\n"); 90 var_dump($expected); 91 } 92 93 if (!empty($values)) { 94 foreach ($values as $value => $constants) { 95 if (count($constants) > 1) { 96 printf("[003] Several constants share the same value '%s'\n", $value); 97 var_dump($constants); 98 } 99 } 100 } 101 102 print "done!"; 103--EXPECT-- 104done! 105