1--TEST-- 2MySQL PDOStatement->bindColumn() 3--EXTENSIONS-- 4pdo_mysql 5--SKIPIF-- 6<?php 7require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); 8MySQLPDOTest::skip(); 9$db = MySQLPDOTest::factory(); 10?> 11--FILE-- 12<?php 13 require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); 14 $db = MySQLPDOTest::factory(); 15 MySQLPDOTest::createTestTable($db); 16 17 try { 18 $db->setAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY, 1); 19 if (1 != $db->getAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY)) 20 printf("[002] Unable to turn on emulated prepared statements\n"); 21 22 $stmt = $db->prepare('SELECT id, label FROM test ORDER BY id ASC LIMIT 2'); 23 $stmt->execute(); 24 $id = $label = null; 25 26 if (!$stmt->bindColumn(1, $id, PDO::PARAM_INT)) 27 printf("[003] Cannot bind integer column, %s %s\n", 28 $stmt->errorCode(), var_export($stmt->errorInfo(), true)); 29 30 if (!$stmt->bindColumn(2, $label, PDO::PARAM_STR)) 31 printf("[004] Cannot bind string column, %s %s\n", 32 $stmt->errorCode(), var_export($stmt->errorInfo(), true)); 33 34 $data = array(); 35 while ($stmt->fetch(PDO::FETCH_BOUND)) { 36 printf("id = %s (%s) / label = %s (%s)\n", 37 var_export($id, true), gettype($id), 38 var_export($label, true), gettype($label)); 39 $data[] = array('id' => $id, 'label' => $label); 40 } 41 42 $stmt = $db->query('SELECT id, label FROM test ORDER BY id ASC LIMIT 2'); 43 $index = 0; 44 while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { 45 if ($row['id'] != $data[$index]['id']) { 46 printf("[005] Fetch bound and fetch assoc differ - column 'id', bound: %s/%s, assoc: %s/%s\n", 47 var_export($data[$index]['id'], true), gettype($data[$index]['id']), 48 var_export($row['id'], true), gettype($row['id'])); 49 } 50 if ($row['label'] != $data[$index]['label']) { 51 printf("[006] Fetch bound and fetch assoc differ - column 'label', bound: %s/%s, assoc: %s/%s\n", 52 var_export($data[$index]['label'], true), gettype($data[$index]['label']), 53 var_export($row['label'], true), gettype($row['label'])); 54 } 55 $index++; 56 } 57 58 $db->setAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY, 0); 59 if (0 != $db->getAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY)) 60 printf("[007] Unable to turn off emulated prepared statements\n"); 61 62 $stmt = $db->prepare('SELECT id, label FROM test ORDER BY id ASC LIMIT 2, 2'); 63 $stmt->execute(); 64 $id = $label = null; 65 66 if (!$stmt->bindColumn(1, $id, PDO::PARAM_INT)) 67 printf("[008] Cannot bind integer column, %s %s\n", 68 $stmt->errorCode(), var_export($stmt->errorInfo(), true)); 69 70 if (!$stmt->bindColumn(2, $label, PDO::PARAM_STR)) 71 printf("[009] Cannot bind string column, %s %s\n", 72 $stmt->errorCode(), var_export($stmt->errorInfo(), true)); 73 74 $data = array(); 75 while ($stmt->fetch(PDO::FETCH_BOUND)) { 76 printf("id = %s (%s) / label = %s (%s)\n", 77 var_export($id, true), gettype($id), 78 var_export($label, true), gettype($label)); 79 $data[] = array('id' => $id, 'label' => $label); 80 } 81 82 $stmt = $db->query('SELECT id, label FROM test ORDER BY id ASC LIMIT 2, 2'); 83 $index = 0; 84 while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { 85 if ($row['id'] != $data[$index]['id']) { 86 printf("[010] Fetch bound and fetch assoc differ - column 'id', bound: %s/%s, assoc: %s/%s\n", 87 var_export($data[$index]['id'], true), gettype($data[$index]['id']), 88 var_export($row['id'], true), gettype($row['id'])); 89 } 90 if ($row['label'] != $data[$index]['label']) { 91 printf("[011] Fetch bound and fetch assoc differ - column 'label', bound: %s/%s, assoc: %s/%s\n", 92 var_export($data[$index]['label'], true), gettype($data[$index]['label']), 93 var_export($row['label'], true), gettype($row['label'])); 94 } 95 $index++; 96 } 97 98 } catch (PDOException $e) { 99 printf("[001] %s [%s] %s\n", 100 $e->getMessage(), $db->errorCode(), implode(' ', $db->errorInfo())); 101 } 102 103 print "done!"; 104?> 105--CLEAN-- 106<?php 107require __DIR__ . '/mysql_pdo_test.inc'; 108$db = MySQLPDOTest::factory(); 109$db->exec('DROP TABLE IF EXISTS test'); 110?> 111--EXPECT-- 112id = 1 (integer) / label = 'a' (string) 113id = 2 (integer) / label = 'b' (string) 114id = 3 (integer) / label = 'c' (string) 115id = 4 (integer) / label = 'd' (string) 116done! 117