MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:uwendel Date:January 31 2008 6:28pm
Subject:PHP mysqlnd svn commit: r1237 - trunk/tests/ext/pdo_mysql
View as plain text  
Author: uwendel
Date: 2008-01-31 19:28:52 +0100 (Thu, 31 Jan 2008)
New Revision: 1237

Added:
   trunk/tests/ext/pdo_mysql/pdo_mysql_prepare_native_dup_named_placeholder.phpt
Log:
Again native and emulated PS return different results. 
We should at least have a warning with native PS that results will be sort
of wrong.


Added: trunk/tests/ext/pdo_mysql/pdo_mysql_prepare_native_dup_named_placeholder.phpt
===================================================================
--- trunk/tests/ext/pdo_mysql/pdo_mysql_prepare_native_dup_named_placeholder.phpt	        
               (rev 0)
+++
trunk/tests/ext/pdo_mysql/pdo_mysql_prepare_native_dup_named_placeholder.phpt	2008-01-31
18:28:52 UTC (rev 1237)
@@ -0,0 +1,85 @@
+--TEST--
+MySQL PDO->prepare(), native PS, named placeholder II
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('mysql_pdo_test.inc');
+MySQLPDOTest::skip();
+$db = MySQLPDOTest::factory();
+?>
+--FILE--
+<?php
+	require_once('mysql_pdo_test.inc');
+	$db = MySQLPDOTest::factory();
+
+	try {
+
+		$db->exec('DROP TABLE IF EXISTS test');
+		$db->exec(sprintf('CREATE TABLE test(id INT, label1 CHAR(255), label2 CHAR(255))
ENGINE=%s', PDO_MYSQL_TEST_ENGINE));
+
+		$db->setAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY, 0);
+		if (0 != $db->getAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY))
+			printf("[002] Unable to turn off emulated prepared statements\n");
+
+		// INSERT a single row
+		$stmt = $db->prepare('INSERT INTO test(id, label1, label2) VALUES (1, :placeholder,
:placeholder)');
+
+		$stmt->execute(array(':placeholder' => 'row1'));
+		if ('00000' !== $stmt->errorCode())
+			printf("[003] Execute has failed, %s %s\n",
+				var_export($stmt->errorCode(), true),
+				var_export($stmt->errorInfo(), true));
+
+		// Ok, what has happened: anything inserted into the DB?
+		$stmt = $db->prepare('SELECT id, label1, label2 FROM test WHERE id = 1');
+		$stmt->execute();
+		var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
+
+		// Now the same with emulated PS.
+		$db->setAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY, 1);
+		if (1 != $db->getAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY))
+			printf("[004] Unable to turn on emulated prepared statements\n");
+
+		$stmt = $db->prepare('INSERT INTO test(id, label1, label2) VALUES(2, :placeholder,
:placeholder)');
+		// No replacement shall be made
+		$stmt->execute(array(':placeholder' => 'row2'));
+		if ('00000' !== $stmt->errorCode())
+			printf("[005] Execute has failed, %s %s\n",
+				var_export($stmt->errorCode(), true),
+				var_export($stmt->errorInfo(), true));
+
+		// Now, what do we have in the DB?
+		$stmt = $db->prepare('SELECT id, label1, label2 FROM test WHERE id = 2');
+		$stmt->execute();
+		var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
+
+	} catch (PDOException $e) {
+		printf("[001] %s [%s] %s\n",
+			$e->getMessage(), $db->errorCode(), implode(' ', $db->errorInfo()));
+	}
+	print "done!";
+?>
+--EXPECTF--
+array(1) {
+  [0]=>
+  array(3) {
+    ["id"]=>
+    string(1) "1"
+    ["label1"]=>
+    string(4) "row1"
+    ["label2"]=>
+    string(1) "row1"
+  }
+}
+array(1) {
+  [0]=>
+  array(3) {
+    ["id"]=>
+    string(1) "2"
+    ["label1"]=>
+    string(4) "row2"
+    ["label2"]=>
+    string(4) "row2"
+  }
+}
+done!
\ No newline at end of file

Thread
PHP mysqlnd svn commit: r1237 - trunk/tests/ext/pdo_mysqluwendel31 Jan