1--TEST--
2MySQL PDO->exec(), affected rows
3--EXTENSIONS--
4pdo_mysql
5--SKIPIF--
6<?php
7require_once __DIR__ . '/inc/mysql_pdo_test.inc';
8MySQLPDOTest::skip();
9?>
10--FILE--
11<?php
12    function exec_and_count($offset, &$db, $sql, $exp, $suppress_warning = false) {
13        try {
14            if ($suppress_warning)
15                $ret = @$db->exec($sql);
16            else
17                $ret = $db->exec($sql);
18
19            if ($ret !== $exp) {
20                printf("[%03d] Expecting '%s'/%s got '%s'/%s when running '%s', [%s] %s\n",
21                    $offset, $exp, gettype($exp), $ret, gettype($ret), $sql,
22                    $db->errorCode(), implode(' ', $db->errorInfo()));
23                return false;
24            }
25
26        } catch (PDOException $e) {
27            printf("[%03d] '%s' has failed, [%s] %s\n",
28                $offset, $sql, $db->errorCode(), implode(' ', $db->errorInfo()));
29            return false;
30        }
31
32        return true;
33    }
34
35    require_once __DIR__ . '/inc/mysql_pdo_test.inc';
36    $db = MySQLPDOTest::factory();
37
38    $db_name = 'pdo_mysql_exec_ddl_db';
39    $db_name_2 = 'pdo_mysql_exec_ddl_db_2';
40    $table = 'pdo_mysql_exec_ddl';
41    $table2 = 'pdo_mysql_exec_ddl_2';
42    /* affected rows related */
43    try {
44        if (1 === @$db->exec("CREATE DATABASE {$db_name}")) {
45            // yippie - we can create databases etc.
46            exec_and_count(3, $db, "ALTER DATABASE {$db_name} CHARACTER SET latin1", 1);
47        }
48
49        if (0 === $db->exec("CREATE TABLE {$table} (id INT, col1 CHAR(2))")) {
50            exec_and_count(5, $db, "CREATE INDEX idx1 ON {$table} (id)", 0);
51            exec_and_count(6, $db, "DROP INDEX idx1 ON {$table}", 0);
52            exec_and_count(7, $db, "ALTER TABLE {$table} DROP id", 0);
53            exec_and_count(8, $db, "ALTER TABLE {$table} ADD id INT", 0);
54            exec_and_count(9, $db, "ALTER TABLE {$table} ALTER id SET DEFAULT 1", 0);
55            exec_and_count(10, $db, "RENAME TABLE {$table} TO {$table2}", 0);
56        }
57
58        /*
59        11.1.2. ALTER LOGFILE GROUP Syntax
60        11.1.3. ALTER SERVER Syntax
61        11.1.5. ALTER TABLESPACE Syntax
62        11.1.8. CREATE LOGFILE GROUP Syntax
63        11.1.9. CREATE SERVER Syntax
64        11.1.11. CREATE TABLESPACE Syntax
65        11.1.14. DROP LOGFILE GROUP Syntax
66        11.1.15. DROP SERVER Syntax
67        11.1.17. DROP TABLESPACE Syntax
68        */
69
70    } catch (PDOException $e) {
71        printf("[001] %s, [%s] %s\n",
72            $e->getMessage(),
73            $db->errorCode(), implode(' ', $db->errorInfo()));
74    }
75
76    print "done!";
77?>
78--CLEAN--
79<?php
80require_once __DIR__ . '/inc/mysql_pdo_test.inc';
81$db = MySQLPDOTest::factory();
82$db->exec('DROP TABLE IF EXISTS pdo_mysql_exec_ddl');
83$db->exec('DROP TABLE IF EXISTS pdo_mysql_exec_ddl_2');
84$db->exec('DROP DATABASE IF EXISTS pdo_mysql_exec_ddl_db');
85$db->exec('DROP DATABASE IF EXISTS pdo_mysql_exec_ddl_db_2');
86?>
87--EXPECT--
88done!
89