<?php require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'; $db = MySQLPDOTest::factory(); function fetch($offset, &$db, $query, $expect = null) { try { $stmt = $db->query('SELECT 1'); $num = $stmt->fetch(PDO::FETCH_NUM); $stmt = $db->query('SELECT 1'); $assoc = $stmt->fetch(PDO::FETCH_ASSOC); $stmt = $db->query('SELECT 1'); $both = $stmt->fetch(PDO::FETCH_BOTH); $computed_both = array_merge($num, $assoc); if ($computed_both != $both) { printf("[%03d] Suspicious FETCH_BOTH result, dumping\n", $offset); var_dump($computed_both); var_dump($both); } if (!is_null($expect) && $expect != $both) { printf("[%03d] Expected differs from returned data, dumping\n", $offset); var_dump($expect); var_dump($both); } } catch (PDOException $e) { printf("[%03d] %s, [%s] %s\n", $offset, $e->getMessage(), $db->errroCode(), implode(' ', $db->errorInfo())); } } try { fetch(2, $db, 'SELECT 1', array(0 => '1', '1' => '1')); } catch (PDOException $e) {
<?php require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'; $pdo = MySQLPDOTest::factory(); $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); $attrs = array(PDO::ATTR_EMULATE_PREPARES => array(null, 1, 0), PDO::MYSQL_ATTR_DIRECT_QUERY => array(null, 0, 1), PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => array(null, 0, 1), PDO::ATTR_AUTOCOMMIT => array(null), PDO::ATTR_PREFETCH => array(null), PDO::ATTR_TIMEOUT => array(null), PDO::ATTR_ERRMODE => array(null), PDO::ATTR_SERVER_VERSION => array(null), PDO::ATTR_CLIENT_VERSION => array(null), PDO::ATTR_SERVER_INFO => array(null), PDO::ATTR_CONNECTION_STATUS => array(null), PDO::ATTR_CASE => array(null), PDO::ATTR_CURSOR_NAME => array(null), PDO::ATTR_CURSOR => array(null), PDO::ATTR_ORACLE_NULLS => array(null), PDO::ATTR_PERSISTENT => array(null), PDO::ATTR_STATEMENT_CLASS => array(null), PDO::ATTR_FETCH_TABLE_NAMES => array(null), PDO::ATTR_FETCH_CATALOG_NAMES => array(null), PDO::ATTR_DRIVER_NAME => array(null), PDO::ATTR_STRINGIFY_FETCHES => array(null), PDO::ATTR_MAX_COLUMN_LEN => array(null), PDO::ATTR_DEFAULT_FETCH_MODE => array(null)); foreach ($attrs as $a => $vals) { foreach ($vals as $v) { try { if (!isset($v)) { var_dump($pdo->getAttribute($a)); } else { $pdo->setAttribute($a, $v); if ($pdo->getAttribute($a) === $v) { echo "OK\n"; } else { throw new \Exception('KO'); } } } catch (\Exception $e) { if ($e->getCode() == 'IM001') { echo "ERR\n"; } else { echo "ERR {$e->getMessage()}\n"; } } } }
<?php require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'; /* Connect to mysql to determine the current charset so we can diffinate it */ $link = MySQLPDOTest::factory(); $charset = $link->query("SHOW VARIABLES LIKE 'character_set_connection'")->fetchObject()->value; /* Make sure that we don't attempt to set the current character set to make this case useful */ $new_charset = $charset == 'latin1' ? 'ascii' : 'latin1'; /* Done with the original connection, create a second link to test the character set being defined */ unset($link); $link = MySQLPDOTest::factory('PDO', false, null, array('charset' => $new_charset)); $conn_charset = $link->query("SHOW VARIABLES LIKE 'character_set_connection'")->fetchObject()->value; if ($charset !== $conn_charset) { echo "done!\n"; } else { echo "failed!\n"; }
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'; $expected = array('MYSQL_ATTR_USE_BUFFERED_QUERY' => true, 'MYSQL_ATTR_LOCAL_INFILE' => true, 'MYSQL_ATTR_DIRECT_QUERY' => true, 'MYSQL_ATTR_FOUND_ROWS' => true, 'MYSQL_ATTR_IGNORE_SPACE' => true, 'MYSQL_ATTR_INIT_COMMAND' => true, "MYSQL_ATTR_SSL_KEY" => true, "MYSQL_ATTR_SSL_CERT" => true, "MYSQL_ATTR_SSL_CA" => true, "MYSQL_ATTR_SSL_CAPATH" => true, "MYSQL_ATTR_SSL_CIPHER" => true, "MYSQL_ATTR_COMPRESS" => true); if (!MySQLPDOTest::isPDOMySQLnd()) { $expected['MYSQL_ATTR_MAX_BUFFER_SIZE'] = true; $expected['MYSQL_ATTR_READ_DEFAULT_FILE'] = true; $expected['MYSQL_ATTR_READ_DEFAULT_GROUP'] = true; } if (extension_loaded('mysqlnd')) { $expected['MYSQL_ATTR_SERVER_PUBLIC_KEY'] = true; } else { if (extension_loaded('mysqli')) { if (mysqli_get_client_version() > 50605) { $expected['MYSQL_ATTR_SERVER_PUBLIC_KEY'] = true; } } else { if (MySQLPDOTest::getClientVersion(MySQLPDOTest::factory()) > 50605) { /* XXX the MySQL client library version isn't exposed with any constants, the single possibility is to use the PDO::getAttribute(). This however will fail with no connection. */ $expected['MYSQL_ATTR_SERVER_PUBLIC_KEY'] = true; } } } /* TODO MYSQLI_OPT_CONNECT_TIMEOUT != PDO::ATTR_TIMEOUT (integer) Sets the timeout value in seconds for communications with the database. ^ Potential BUG, PDO::ATTR_TIMEOUT is used in pdo_mysql_handle_factory MYSQLI_SET_CHARSET_NAME -> DSN/charset=<charset_name>