PHP  
 PHP_5_6
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

Test Failure Report for ext/pdo_mysql/tests/pdo_mysql_prepare_native_dup_named_placeholder.phpt ('MySQL PDO->prepare(), native PS, named placeholder II')

Script

1: <?php
2:     
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR 'mysql_pdo_test.inc');
3:     
$db MySQLPDOTest::factory();
4:
5:     try {
6:
7:         
$db->exec('DROP TABLE IF EXISTS test');
8:         
$db->exec(sprintf('CREATE TABLE test(id INT, label1 CHAR(255), label2 CHAR(255)) ENGINE=%s'PDO_MYSQL_TEST_ENGINE));
9:
10:         
$db->setAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY0);
11:         if (
!= $db->getAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY))
12:             
printf("[002] Unable to turn off emulated prepared statements\n");
13:         
printf("Native...\n");
14:
15:         
// INSERT a single row
16:         
$stmt $db->prepare('INSERT INTO test(id, label1, label2) VALUES (1, :placeholder, :placeholder)');
17:
18:         
$stmt->execute(array(':placeholder' => 'row1'));
19:         if (
'00000' !== $stmt->errorCode())
20:             
printf("[003] Execute has failed, %s %s\n",
21:                 
var_export($stmt->errorCode(), true),
22:                 
var_export($stmt->errorInfo(), true));
23:
24:         
// Ok, what has happened: anything inserted into the DB?
25:         
$stmt $db->prepare('SELECT id, label1, label2 FROM test WHERE id = 1');
26:         
$stmt->execute();
27:         
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
28:
29:         
// Now the same with emulated PS.
30:         
$db->setAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY1);
31:         if (
!= $db->getAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY))
32:             
printf("[004] Unable to turn on emulated prepared statements\n");
33:         
printf("Emulated...\n");
34:
35:         
$stmt $db->prepare('INSERT INTO test(id, label1, label2) VALUES(2, :placeholder, :placeholder)');
36:         
// No replacement shall be made
37:         
$stmt->execute(array(':placeholder' => 'row2'));
38:         if (
'00000' !== $stmt->errorCode())
39:             
printf("[005] Execute has failed, %s %s\n",
40:                 
var_export($stmt->errorCode(), true),
41:                 
var_export($stmt->errorInfo(), true));
42:
43:         
// Now, what do we have in the DB?
44:         
$stmt $db->prepare('SELECT id, label1, label2 FROM test WHERE id = 2');
45:         
$stmt->execute();
46:         
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
47:
48:         
//
49:         // Another variation of the theme
50:         //
51:
52:         
$db->exec('DELETE FROM test');
53:         
$db->exec("INSERT INTO test (id, label1, label2) VALUES (1, 'row1', 'row2')");
54:         
$sql "SELECT id, label1 FROM test WHERE id = :placeholder AND label1 = (SELECT label1 AS 'SELECT' FROM test WHERE id = :placeholder)";
55:
56:         
// emulated...
57:         
$stmt $db->prepare($sql);
58:         
$stmt->execute(array(':placeholder' => 1));
59:         if (
'00000' !== $stmt->errorCode())
60:             
printf("[006] Execute has failed, %s %s\n",
61:                 
var_export($stmt->errorCode(), true),
62:                 
var_export($stmt->errorInfo(), true));
63:         
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
64:
65:         
// native...
66:         
$db->setAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY0);
67:         if (
!= $db->getAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY))
68:             
printf("[007] Unable to turn off emulated prepared statements\n");
69:         
printf("Native...\n");
70:
71:         
$stmt $db->prepare($sql);
72:         
$stmt->execute(array(':placeholder' => 1));
73:         if (
'00000' !== $stmt->errorCode())
74:             
printf("[008] Execute has failed, %s %s\n",
75:                 
var_export($stmt->errorCode(), true),
76:                 
var_export($stmt->errorInfo(), true));
77:         
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
78:
79:
80:     } catch (
PDOException $e) {
81:         
printf("[001] %s [%s] %s\n",
82:             
$e->getMessage(), $db->errorCode(), implode(' '$db->errorInfo()));
83:     }
84:
85:     print 
"done!";
86:
?>
87:

Expected

Native...

Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number in %s on line %d
[003] Execute has failed, 'HY093' array (
  0 => 'HY093',
  1 => NULL,
  2 => NULL,
)
array(0) {
}
Emulated...
array(1) {
  [0]=>
  array(3) {
    ["id"]=>
    string(1) "2"
    ["label1"]=>
    string(4) "row2"
    ["label2"]=>
    string(4) "row2"
  }
}
array(1) {
  [0]=>
  array(2) {
    ["id"]=>
    string(1) "1"
    ["label1"]=>
    string(4) "row1"
  }
}
Native...

Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number in %s on line %d
[008] Execute has failed, 'HY093' array (
  0 => 'HY093',
  1 => NULL,
  2 => NULL,
)
array(0) {
}
done!

Output

Native...

Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number in /var/php_gcov/PHP_5_6/ext/pdo_mysql/tests/pdo_mysql_prepare_native_dup_named_placeholder.php on line 18
[003] Execute has failed, 'HY093' array (
  0 => 'HY093',
  1 => NULL,
  2 => NULL,
)
Out of memory

Diff

009+ Out of memory
009- array(0) {
010- }
011- Emulated...
012- array(1) {
013-   [0]=>
014-   array(3) {
015-     ["id"]=>
016-     string(1) "2"
017-     ["label1"]=>
018-     string(4) "row2"
019-     ["label2"]=>
020-     string(4) "row2"
021-   }
022- }
023- array(1) {
024-   [0]=>
025-   array(2) {
026-     ["id"]=>
027-     string(1) "1"
028-     ["label1"]=>
029-     string(4) "row1"
030-   }
031- }
032- Native...
033- 
034- Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number in %s on line %d
035- [008] Execute has failed, 'HY093' array (
036-   0 => 'HY093',
037-   1 => NULL,
038-   2 => NULL,
039- )
040- array(0) {
041- }
042- done!

 

Generated at Mon, 27 Nov 2017 05:04:32 +0000 (16 days ago)

Copyright © 2005-2017 The PHP Group
All rights reserved.