1--TEST--
2MySQL PDOStatement->closeCursor()
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
16
17    try {
18
19        $db->setAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY, 0);
20        if (0 != $db->getAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY))
21            printf("[002] Unable to turn off emulated prepared statements\n");
22
23        $db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
24        MySQLPDOTest::createTestTable($db);
25
26        $stmt = $db->prepare('SELECT id, label FROM test WHERE id > ? ORDER BY id ASC LIMIT 2');
27        $in = 0;
28        if (!$stmt->bindParam(1, $in))
29            printf("[003] Cannot bind parameter, %s %s\n",
30                $stmt->errorCode(), var_export($stmt->errorInfo(), true));
31
32        $stmt->execute();
33        $id = $label = null;
34
35        if (!$stmt->bindColumn(1, $id, PDO::PARAM_INT))
36            printf("[004] Cannot bind integer column, %s %s\n",
37                $stmt->errorCode(), var_export($stmt->errorInfo(), true));
38
39        if (!$stmt->bindColumn(2, $label, PDO::PARAM_STR))
40            printf("[005] Cannot bind string column, %s %s\n",
41                $stmt->errorCode(), var_export($stmt->errorInfo(), true));
42
43        while ($stmt->fetch(PDO::FETCH_BOUND))
44            printf("in = %d -> id = %s (%s) / label = %s (%s)\n",
45                $in,
46                var_export($id, true), gettype($id),
47                var_export($label, true), gettype($label));
48
49        $stmt->closeCursor();
50        $stmt->execute();
51        while ($stmt->fetch(PDO::FETCH_BOUND))
52            printf("in = %d -> id = %s (%s) / label = %s (%s)\n",
53                $in,
54                var_export($id, true), gettype($id),
55                var_export($label, true), gettype($label));
56
57    } catch (PDOException $e) {
58        printf("[001] %s [%s] %s\n",
59            $e->getMessage(), $db->errorCode(), implode(' ', $db->errorInfo()));
60    }
61
62    $db->exec('DROP TABLE IF EXISTS test');
63    print "done!";
64?>
65--CLEAN--
66<?php
67require __DIR__ . '/mysql_pdo_test.inc';
68MySQLPDOTest::dropTestTable();
69?>
70--EXPECT--
71in = 0 -> id = 1 (integer) / label = 'a' (string)
72in = 0 -> id = 2 (integer) / label = 'b' (string)
73in = 0 -> id = 1 (integer) / label = 'a' (string)
74in = 0 -> id = 2 (integer) / label = 'b' (string)
75done!
76