~ubuntu-branches/ubuntu/quantal/php5/quantal

« back to all changes in this revision

Viewing changes to ext/pdo_mysql/tests/pdo_mysql_prepare_native_clear_error.phpt

  • Committer: Bazaar Package Importer
  • Author(s): Sean Finney
  • Date: 2009-07-01 09:12:10 UTC
  • mto: (0.9.1) (1.1.17 upstream)
  • mto: This revision was merged to the branch mainline in revision 58.
  • Revision ID: james.westby@ubuntu.com-20090701091210-go0h6506p62on17r
Tags: upstream-5.3.0
ImportĀ upstreamĀ versionĀ 5.3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
--TEST--
 
2
MySQL PDO->prepare(), native PS, clear line after error
 
3
--SKIPIF--
 
4
<?php
 
5
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'skipif.inc');
 
6
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
 
7
MySQLPDOTest::skip();
 
8
$db = MySQLPDOTest::factory();
 
9
?>
 
10
--FILE--
 
11
<?php
 
12
        require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
 
13
        $db = MySQLPDOTest::factory();
 
14
 
 
15
        try {
 
16
 
 
17
                $db->exec('DROP TABLE IF EXISTS test');
 
18
                $db->exec(sprintf('CREATE TABLE test(id INT, label CHAR(255)) ENGINE=%s', PDO_MYSQL_TEST_ENGINE));
 
19
 
 
20
                // We need to run the emulated version first. Native version will cause a fatal error
 
21
                $db->setAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY, 1);
 
22
                if (1 != $db->getAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY))
 
23
                        printf("[002] Unable to turn on emulated prepared statements\n");
 
24
 
 
25
                // INSERT a single row
 
26
                $db->exec('INSERT INTO test(id, label) VALUES (1, "row1")');
 
27
 
 
28
                $stmt = $db->prepare('SELECT unknown_column FROM test WHERE id > :placeholder ORDER BY id ASC');
 
29
                $stmt->execute(array(':placeholder' => 0));
 
30
                if ('00000' !== $stmt->errorCode())
 
31
                        printf("[003] Execute has failed, %s %s\n",
 
32
                                var_export($stmt->errorCode(), true),
 
33
                                var_export($stmt->errorInfo(), true));
 
34
 
 
35
                $stmt = $db->prepare('SELECT id, label FROM test WHERE id > :placeholder ORDER BY id ASC');
 
36
                $stmt->execute(array(':placeholder' => 0));
 
37
                if ('00000' !== $stmt->errorCode())
 
38
                        printf("[004] Execute has failed, %s %s\n",
 
39
                                var_export($stmt->errorCode(), true),
 
40
                                var_export($stmt->errorInfo(), true));
 
41
                var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
 
42
 
 
43
                // Native PS
 
44
                $db->setAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY, 0);
 
45
                if (0 != $db->getAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY))
 
46
                        printf("[005] Unable to turn off emulated prepared statements\n");
 
47
 
 
48
                $stmt = $db->prepare('SELECT unknown_column FROM test WHERE id > :placeholder ORDER BY id ASC');
 
49
                $stmt->execute(array(':placeholder' => 0));
 
50
                if ('00000' !== $stmt->errorCode())
 
51
                        printf("[006] Execute has failed, %s %s\n",
 
52
                                var_export($stmt->errorCode(), true),
 
53
                                var_export($stmt->errorInfo(), true));
 
54
 
 
55
                $stmt = $db->prepare('SELECT id, label FROM test WHERE id > :placeholder ORDER BY id ASC');
 
56
                $stmt->execute(array(':placeholder' => 0));
 
57
                if ('00000' !== $stmt->errorCode())
 
58
                        printf("[007] Execute has failed, %s %s\n",
 
59
                                var_export($stmt->errorCode(), true),
 
60
                                var_export($stmt->errorInfo(), true));
 
61
                var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
 
62
 
 
63
 
 
64
        } catch (PDOException $e) {
 
65
                printf("[001] %s [%s] %s\n",
 
66
                        $e->getMessage(), $db->errorCode(), implode(' ', $db->errorInfo()));
 
67
        }
 
68
 
 
69
        $db->exec('DROP TABLE IF EXISTS test');
 
70
        print "done!";
 
71
?>
 
72
--EXPECTF--
 
73
Warning: PDOStatement::execute(): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'unknown_column' in 'field list' in %s on line %d
 
74
[003] Execute has failed, '42S22' array (
 
75
  0 => '42S22',
 
76
  1 => 1054,
 
77
  2 => 'Unknown column \'unknown_column\' in \'field list\'',
 
78
)
 
79
array(1) {
 
80
  [0]=>
 
81
  array(2) {
 
82
    ["id"]=>
 
83
    string(1) "1"
 
84
    ["label"]=>
 
85
    string(4) "row1"
 
86
  }
 
87
}
 
88
 
 
89
Warning: PDO::prepare(): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'unknown_column' in 'field list' in %s on line %d
 
90
 
 
91
Fatal error: Call to a member function execute() on a non-object in %s on line %d
 
 
b'\\ No newline at end of file'