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_named_placeholder.phpt ('MySQL PDO->prepare(), native PS, named placeholder')

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, label 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:
14:         
// INSERT a single row
15:         
$stmt $db->prepare("INSERT INTO test(id, label) VALUES (100, ':placeholder')");
16:
17:         
// Yes, there is no placeholder to bind to and named placeholder
18:         // do not work with MySQL native PS, but lets see what happens!
19:         // The ':placeholder' is a string constant in the INSERT statement.
20:         // I would expect to get an error message, but this is not what happens.
21:         
$stmt->execute(array(':placeholder' => 'row1'));
22:         if (
'00000' !== $stmt->errorCode())
23:             
printf("[003] Execute has failed, %s %s\n",
24:                 
var_export($stmt->errorCode(), true),
25:                 
var_export($stmt->errorInfo(), true));
26:
27:         
// Ok, what has happened: anything inserted into the DB?
28:         
$stmt $db->prepare('SELECT id, label FROM test');
29:         
$stmt->execute();
30:         
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
31:
32:         
// Now the same with emulated PS.
33:         
$db->setAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY1);
34:         if (
!= $db->getAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY))
35:             
printf("[004] Unable to turn on emulated prepared statements\n");
36:
37:         
// Note that the "named placeholder" is enclosed by double quotes.
38:         
$stmt $db->prepare("INSERT INTO test(id, label) VALUES(101, ':placeholder')");
39:         
// No replacement shall be made
40:         
$stmt->execute(array(':placeholder' => 'row1'));
41:         
// Again, I'd like to see an error message
42:         
if ('00000' !== $stmt->errorCode())
43:             
printf("[005] Execute has failed, %s %s\n",
44:                 
var_export($stmt->errorCode(), true),
45:                 
var_export($stmt->errorInfo(), true));
46:
47:         
// Now, what do we have in the DB?
48:         
$stmt $db->prepare('SELECT id, label FROM test ORDER BY id');
49:         
$stmt->execute();
50:         
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
51:
52:     } catch (
PDOException $e) {
53:         
printf("[001] %s [%s] %s\n",
54:             
$e->getMessage(), $db->errorCode(), implode(' '$db->errorInfo()));
55:     }
56:
57:     print 
"done!";
58:
?>
59:

Expected

[003] Execute has failed, 'HY093' array (
  0 => 'HY093',
  1 => NULL,
  2 => NULL,
)
array(0) {
}
array(1) {
  [0]=>
  array(2) {
    ["id"]=>
    string(3) "101"
    ["label"]=>
    string(12) ":placeholder"
  }
}
done!

Output

[003] Execute has failed, 'HY093' array (
  0 => 'HY093',
  1 => NULL,
  2 => NULL,
)
Out of memory

Diff

006+ Out of memory
006- array(0) {
007- }
008- array(1) {
009-   [0]=>
010-   array(2) {
011-     ["id"]=>
012-     string(3) "101"
013-     ["label"]=>
014-     string(12) ":placeholder"
015-   }
016- }
017- done!

 

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

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