Author: uwendel
Date: 2008-03-11 12:21:08 +0100 (Tue, 11 Mar 2008)
New Revision: 1344
Added:
trunk/tests/ext/pdo_mysql/pdo_mysql_stmt_fetch_serialize_simple.phpt
Log:
At its best PDO::FETCH_SERIALIZE is half-baken...
Added: trunk/tests/ext/pdo_mysql/pdo_mysql_stmt_fetch_serialize_simple.phpt
===================================================================
--- trunk/tests/ext/pdo_mysql/pdo_mysql_stmt_fetch_serialize_simple.phpt
(rev 0)
+++ trunk/tests/ext/pdo_mysql/pdo_mysql_stmt_fetch_serialize_simple.phpt 2008-03-11
11:21:08 UTC (rev 1344)
@@ -0,0 +1,72 @@
+--TEST--
+MySQL PDOStatement->fetch(), PDO::FETCH_SERIALIZE
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('mysql_pdo_test.inc');
+MySQLPDOTest::skip();
+if (version_compare(PHP_VERSION, '5.1.0', '<'))
+ die("skip Needs 5.1.0 and Interface Serializable");
+?>
+--FILE--
+<?php
+ require_once('mysql_pdo_test.inc');
+ $db = MySQLPDOTest::factory();
+
+ try {
+
+ class myclass implements Serializable {
+
+ public function __construct($caller = null) {
+ printf("%s(%s) - note that it must not be called when unserializing\n", __METHOD__,
var_export($caller, true));
+ }
+
+ public function __set($prop, $value) {
+ printf("%s(%s, %s)\n", __METHOD__, var_export($prop, true), var_export($value,
true));
+ $this->{$prop} = $value;
+ }
+
+ public function serialize() {
+ printf("%s()\n", __METHOD__);
+ return 'Value from serialize()';
+ }
+
+ public function unserialize($data) {
+ printf("%s(%s)\n", __METHOD__, var_export($data, true));
+ }
+
+ }
+
+ printf("Lets see what the Serializeable interface makes our object behave like...\n");
+ $obj = new myclass('Called by script');
+ $tmp = unserialize(serialize($obj));
+ var_dump($tmp);
+
+ printf("\nAnd now magic PDO using
fetchAll(PDO::FETCH_CLASS|PDO::FETCH_SERIALIZE)...\n");
+ $db->exec('DROP TABLE IF EXISTS test');
+ $db->exec(sprintf('CREATE TABLE test(myobj BLOB) ENGINE=%s',
MySQLPDOTest::getTableEngine()));
+ $db->exec('INSERT INTO test(myobj) VALUES ("Data fetched from DB to be given to
unserialize()")');
+
+ $stmt = $db->prepare('SELECT myobj FROM test');
+ $stmt->execute();
+ $rows = $stmt->fetchAll(PDO::FETCH_CLASS|PDO::FETCH_SERIALIZE, 'myclass',
array('Called by PDO'));
+ var_dump($rows[0]);
+
+ $stmt->execute();
+ $rows = $stmt->fetchAll(PDO::FETCH_CLASS|PDO::FETCH_SERIALIZE, 'myclass');
+ var_dump($rows[0]);
+
+ printf("\nAnd now PDO using setFetchMode(PDO::FETCH:CLASS|PDO::FETCH_SERIALIZE) +
fetch()...\n");
+ $stmt = $db->prepare('SELECT myobj FROM test');
+ $stmt->setFetchMode(PDO::FETCH_CLASS|PDO::FETCH_SERIALIZE, 'myclass', array('Called
by PDO'));
+ $stmt->execute();
+ var_dump($stmt->fetch());
+
+ } catch (PDOException $e) {
+ printf("[001] %s [%s] %s\n",
+ $e->getMessage(), $db->errorCode(), implode(' ', $db->errorInfo()));
+ }
+ print "done!\n";
+?>
+--EXPECTF--
+BOGUS
\ No newline at end of file
| Thread |
|---|
| • PHP mysqlnd svn commit: r1344 - trunk/tests/ext/pdo_mysql | uwendel | 11 Mar |