summaryrefslogtreecommitdiff
path: root/ext/pdo_mysql/tests/pdo_mysql_stmt_blobs.phpt
diff options
context:
space:
mode:
authorJohannes Schlüter <johannes@php.net>2008-07-21 13:05:51 +0000
committerJohannes Schlüter <johannes@php.net>2008-07-21 13:05:51 +0000
commitae1cd8e253ff1a38a07b7d6636cdc57bfe73b1b0 (patch)
tree1be53da74ed05784774bb8b53eb7ac33066f7681 /ext/pdo_mysql/tests/pdo_mysql_stmt_blobs.phpt
parent0df974b7a599ae424bc7f80c23b4c721d689ce9c (diff)
downloadphp-git-ae1cd8e253ff1a38a07b7d6636cdc57bfe73b1b0.tar.gz
- Add mysqlnd support for PDO_mysql, fixes at least bug#41997,#42499,
pecl#12794, pecl#12401 # Running the tests: # (Note: Doesn't work currnetly on HEAD, see: # http://news.php.net/php.qa/64378) # # PDO_MYSQL_TEST_DSN - DSN # For example: mysql:dbname=test;host=localhost;port=3306 # # PDO_MYSQL_TEST_HOST - database host # PDO_MYSQL_TEST_DB - database (schema) name # PDO_MYSQL_TEST_SOCKET - database server socket # PDO_MYSQL_TEST_ENGINE - storage engine to use # PDO_MYSQL_TEST_USER - database user # PDO_MYSQL_TEST_PASS - database user password # PDO_MYSQL_TEST_CHARSET - database charset # # NOTE: if any of PDO_MYSQL_TEST_[HOST|DB|SOCKET|ENGINE|CHARSET] is # part of PDO_MYSQL_TEST_DSN, the values must match. That is, for example, # for PDO_MYSQL_TEST_DSN = mysql:dbname=test you MUST set PDO_MYSQL_TEST_DB=test.
Diffstat (limited to 'ext/pdo_mysql/tests/pdo_mysql_stmt_blobs.phpt')
-rw-r--r--ext/pdo_mysql/tests/pdo_mysql_stmt_blobs.phpt91
1 files changed, 91 insertions, 0 deletions
diff --git a/ext/pdo_mysql/tests/pdo_mysql_stmt_blobs.phpt b/ext/pdo_mysql/tests/pdo_mysql_stmt_blobs.phpt
new file mode 100644
index 0000000000..2914583f6b
--- /dev/null
+++ b/ext/pdo_mysql/tests/pdo_mysql_stmt_blobs.phpt
@@ -0,0 +1,91 @@
+--TEST--
+MySQL Prepared Statements and BLOBs
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'skipif.inc');
+require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
+MySQLPDOTest::skip();
+?>
+--FILE--
+<?php
+ require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
+ $db = MySQLPDOTest::factory();
+
+ $blobs = array(
+ 'TINYBLOB' => 255,
+ 'TINYTEXT' => 255,
+ 'BLOB' => 32767,
+ 'TEXT' => 32767,
+ 'MEDIUMBLOB' => 100000,
+ 'MEDIUMTEXT' => 100000,
+ 'LONGBLOB' => 100000,
+ 'LONGTEXT' => 100000,
+ );
+
+ function test_blob($db, $offset, $sql_type, $test_len) {
+
+ $db->exec('DROP TABLE IF EXISTS test');
+ $db->exec(sprintf('CREATE TABLE test(id INT, label %s) ENGINE=%s', $sql_type, PDO_MYSQL_TEST_ENGINE));
+
+ $value = str_repeat('a', $test_len);
+ $stmt = $db->prepare('INSERT INTO test(id, label) VALUES (?, ?)');
+ $stmt->bindValue(1, 1);
+ $stmt->bindValue(2, $value);
+ if (!$stmt->execute()) {
+ printf("[%03d + 1] %d %s\n",
+ $offset, $stmt->errorCode(), var_export($stmt->errorInfo(), true));
+ return false;
+ }
+
+ $stmt = $db->query('SELECT id, label FROM test');
+ $id = $label = NULL;
+ $stmt->bindColumn(1, $id, PDO::PARAM_INT);
+ $stmt->bindColumn(2, $label, PDO::PARAM_LOB);
+
+ if (!$stmt->fetch(PDO::FETCH_BOUND)) {
+ printf("[%03d + 2] %d %s\n",
+ $offset, $stmt->errorCode(), var_export($stmt->errorInfo(), true));
+ return false;
+ }
+
+ if ($label !== $value) {
+ printf("[%03d + 3] Returned value seems to be wrong (%d vs. %d charachters). Check manually\n",
+ $offset, strlen($label), strlen($value));
+ return false;
+ }
+
+ if (1 != $id) {
+ printf("[%03d + 3] Returned id column value seems wrong, expecting 1 got %s.\n",
+ $offset, var_export($id, true));
+ return false;
+ }
+
+ $stmt = $db->query('SELECT id, label FROM test');
+ $ret = $stmt->fetch(PDO::FETCH_ASSOC);
+
+ if ($ret['label'] !== $value) {
+ printf("[%03d + 3] Returned value seems to be wrong (%d vs. %d charachters). Check manually\n",
+ $offset, strlen($ret['label']), strlen($value));
+ return false;
+ }
+
+ if (1 != $ret['id']) {
+ printf("[%03d + 3] Returned id column value seems wrong, expecting 1 got %s.\n",
+ $offset, var_export($ret['id'], true));
+ return false;
+ }
+
+ return true;
+ }
+
+ $offset = 0;
+ foreach ($blobs as $sql_type => $test_len) {
+ $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1);
+ test_blob($db, ++$offset, $sql_type, $test_len);
+ $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0);
+ test_blob($db, ++$offset, $sql_type, $test_len);
+ }
+
+ print "done!";
+--EXPECTF--
+done! \ No newline at end of file