PHP  
 PHP_5_4
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_stmt_variable_columncount.phpt ('MySQL Prepared Statements and different column counts')

Script

1: <?php
2:     
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR 'mysql_pdo_test.inc');
3:     
$db MySQLPDOTest::factory();
4:
5:     function 
check_result($offset$stmt$columns) {
6:
7:         do {
8:                 
$row $stmt->fetch(PDO::FETCH_ASSOC);
9:         } while (
$stmt->nextRowSet());
10:
11:         if (!isset(
$row['one']) || ($row['one'] != 1)) {
12:                 
printf("[%03d + 1] Expecting array('one' => 1), got %s\n"$offsetvar_export($rowtrue));
13:                 return 
false;
14:         }
15:
16:         if ((
$columns == 2) &&
17:             (!isset(
$row['two']) || ($row['two'] != 2))) {
18:                 
printf("[%03d + 2] Expecting array('one' => 1, 'two' => 2), got %s\n"$offsetvar_export($rowtrue));
19:                 return 
false;
20:         } else if ((
$columns == 1) && isset($row['two'])) {
21:                 
printf("[%03d + 3] Expecting one array element got two\n"$offset);
22:                 return 
false;
23:         }
24:
25:         return 
true;
26:     }
27:
28:     try {
29:
30:         
// What will happen if a PS returns a differen number of result set column upon each execution?
31:         // Lets try with a SP accepting parameters...
32:         
$db->exec('DROP PROCEDURE IF EXISTS p');
33:         
$db->exec('CREATE PROCEDURE p(IN cols INT) BEGIN IF cols < 2 THEN SELECT cols AS "one"; ELSE SELECT 1 AS "one", cols AS "two"; END IF; END;');
34:
35:         
// Emulates PS first
36:         
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES1);
37:         
$stmt $db->prepare('CALL p(?)');
38:
39:         
$columns null;
40:         
$stmt->bindParam(1$columns);
41:         for (
$i 0$i 5$i++) {
42:             
$columns = ($i 2) + 1;
43:             
$stmt->execute();
44:             
check_result($i$stmt$columns);
45:         }
46:
47:         if (
MySQLPDOTest::isPDOMySQLnd()) {
48:             
// Native PS
49:             // Libmysql cannot handle such a stored procedure. You will see leaks with libmysql
50:             
$db MySQLPDOTest::factory();
51:             
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES0);
52:             
$db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY1);
53:             
$stmt $db->prepare('CALL p(?)');
54:             
$stmt->bindParam(1$columns);
55:             for (
$i 5$i 10$i++) {
56:                 
$columns = ($i 2) + 1;
57:                 
$stmt->execute();
58:                 
check_result($i$stmt$columns);
59:             }
60:         }
61:
62:         
// And now without parameters... - this gives a different control flow inside PDO
63:         
$db->exec('DROP PROCEDURE IF EXISTS p');
64:         
$db->exec('CREATE PROCEDURE p() BEGIN DECLARE cols INT; SELECT @numcols INTO cols; IF cols < 2 THEN SET @numcols = 2; SELECT cols AS "one"; ELSE SET @numcols = 1; SELECT 1 AS "one", cols AS "two"; END IF; END;');
65:
66:                 
// Emulates PS first
67:         
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES1);
68:         
$db->exec('SET @numcols = 1');
69:         
$stmt $db->prepare('CALL p()');
70:         
$stmt->execute();
71:         
check_result(11$stmt1);
72:         
$stmt->execute();
73:         
check_result(12$stmt2);
74:         
$db->exec('SET @numcols = 1');
75:         
$stmt->execute();
76:         
check_result(13$stmt1);
77:
78:         if (
MySQLPDOTest::isPDOMySQLnd()) {
79:             
// Native PS
80:             // Libmysql cannot handle such a stored procedure. You will see leaks with libmysql
81:             
$db MySQLPDOTest::factory();
82:             
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES0);
83:             
$db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY1);
84:             
$db->exec('SET @numcols = 1');
85:             
$stmt $db->prepare('CALL p()');
86:             
$stmt->execute();
87:             
check_result(14$stmt1);
88:             
$stmt->execute();
89:             
check_result(15$stmt2);
90:             
$db->exec('SET @numcols = 1');
91:             
$stmt->execute();
92:             
check_result(16$stmt1);
93:         }
94:
95:     } catch (
PDOException $e) {
96:         
printf("[99] %s [%s] %s\n",
97:             
$e->getMessage(), $db->errorCode(), implode(' '$db->errorInfo()));
98:     }
99:
100:     print 
"done!";
101:
?>
102:

Expected

done!

Output

Warning: PDOStatement::fetch(): SQLSTATE[HY000]: General error in /var/php_gcov/PHP_5_4/ext/pdo_mysql/tests/pdo_mysql_stmt_variable_columncount.php on line 8
[000 + 1] Expecting array('one' => 1), got false

Warning: PDOStatement::fetch(): SQLSTATE[HY000]: General error in /var/php_gcov/PHP_5_4/ext/pdo_mysql/tests/pdo_mysql_stmt_variable_columncount.php on line 8
[001 + 1] Expecting array('one' => 1), got false

Warning: PDOStatement::fetch(): SQLSTATE[HY000]: General error in /var/php_gcov/PHP_5_4/ext/pdo_mysql/tests/pdo_mysql_stmt_variable_columncount.php on line 8
[002 + 1] Expecting array('one' => 1), got false

Warning: PDOStatement::fetch(): SQLSTATE[HY000]: General error in /var/php_gcov/PHP_5_4/ext/pdo_mysql/tests/pdo_mysql_stmt_variable_columncount.php on line 8
[003 + 1] Expecting array('one' => 1), got false

Warning: PDOStatement::fetch(): SQLSTATE[HY000]: General error in /var/php_gcov/PHP_5_4/ext/pdo_mysql/tests/pdo_mysql_stmt_variable_columncount.php on line 8
[004 + 1] Expecting array('one' => 1), got false

Warning: PDOStatement::fetch(): SQLSTATE[HY000]: General error in /var/php_gcov/PHP_5_4/ext/pdo_mysql/tests/pdo_mysql_stmt_variable_columncount.php on line 8
[011 + 1] Expecting array('one' => 1), got false

Warning: PDOStatement::fetch(): SQLSTATE[HY000]: General error in /var/php_gcov/PHP_5_4/ext/pdo_mysql/tests/pdo_mysql_stmt_variable_columncount.php on line 8
[012 + 1] Expecting array('one' => 1), got false

Warning: PDOStatement::fetch(): SQLSTATE[HY000]: General error in /var/php_gcov/PHP_5_4/ext/pdo_mysql/tests/pdo_mysql_stmt_variable_columncount.php on line 8
[013 + 1] Expecting array('one' => 1), got false
done!

Diff

001+ Warning: PDOStatement::fetch(): SQLSTATE[HY000]: General error in /var/php_gcov/PHP_5_4/ext/pdo_mysql/tests/pdo_mysql_stmt_variable_columncount.php on line 8
001- done!
002+ [000 + 1] Expecting array('one' => 1), got false
003+ 
004+ Warning: PDOStatement::fetch(): SQLSTATE[HY000]: General error in /var/php_gcov/PHP_5_4/ext/pdo_mysql/tests/pdo_mysql_stmt_variable_columncount.php on line 8
005+ [001 + 1] Expecting array('one' => 1), got false
006+ 
007+ Warning: PDOStatement::fetch(): SQLSTATE[HY000]: General error in /var/php_gcov/PHP_5_4/ext/pdo_mysql/tests/pdo_mysql_stmt_variable_columncount.php on line 8
008+ [002 + 1] Expecting array('one' => 1), got false
009+ 
010+ Warning: PDOStatement::fetch(): SQLSTATE[HY000]: General error in /var/php_gcov/PHP_5_4/ext/pdo_mysql/tests/pdo_mysql_stmt_variable_columncount.php on line 8
011+ [003 + 1] Expecting array('one' => 1), got false
012+ 
013+ Warning: PDOStatement::fetch(): SQLSTATE[HY000]: General error in /var/php_gcov/PHP_5_4/ext/pdo_mysql/tests/pdo_mysql_stmt_variable_columncount.php on line 8
014+ [004 + 1] Expecting array('one' => 1), got false
015+ 
016+ Warning: PDOStatement::fetch(): SQLSTATE[HY000]: General error in /var/php_gcov/PHP_5_4/ext/pdo_mysql/tests/pdo_mysql_stmt_variable_columncount.php on line 8
017+ [011 + 1] Expecting array('one' => 1), got false
018+ 
019+ Warning: PDOStatement::fetch(): SQLSTATE[HY000]: General error in /var/php_gcov/PHP_5_4/ext/pdo_mysql/tests/pdo_mysql_stmt_variable_columncount.php on line 8
020+ [012 + 1] Expecting array('one' => 1), got false
021+ 
022+ Warning: PDOStatement::fetch(): SQLSTATE[HY000]: General error in /var/php_gcov/PHP_5_4/ext/pdo_mysql/tests/pdo_mysql_stmt_variable_columncount.php on line 8
023+ [013 + 1] Expecting array('one' => 1), got false
024+ done!

 

Generated at Sat, 13 Sep 2014 16:24:41 +0000 (7 days ago)

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