PHP  
 PHP_5_3
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_exec_load_data.phpt ('MySQL PDO->exec(), affected rows')

Script

1: <?php
2:     
function exec_and_count($offset, &$db$sql$exp) {
3:
4:         try {
5:
6:             
$ret $db->exec($sql);
7:             if (
$ret !== $exp) {
8:                 
printf("[%03d] Expecting '%s'/%s got '%s'/%s when running '%s', [%s] %s\n",
9:                     
$offset$expgettype($exp), $retgettype($ret), $sql,
10:                     
$db->errorCode(), implode(' '$db->errorInfo()));
11:                 return 
false;
12:             }
13:
14:         } catch (
PDOException $e) {
15:
16:             if (
42000 == $db->errorCode()) {
17:                 
// Error: 1148 SQLSTATE: 42000  (ER_NOT_ALLOWED_COMMAND)
18:                 // Load data infile not allowed
19:                 
return false;
20:             }
21:
22:             
printf("[%03d] '%s' has failed, [%s] %s\n",
23:                 
$offset$sql$db->errorCode(), implode(' '$db->errorInfo()));
24:             return 
false;
25:         }
26:
27:         return 
true;
28:     }
29:
30:     require_once(
dirname(__FILE__) . DIRECTORY_SEPARATOR 'mysql_pdo_test.inc');
31:     
$db MySQLPDOTest::factory();
32:     
MySQLPDOTest::createTestTable($dbMySQLPDOTest::detect_transactional_mysql_engine($db));
33:
34:     
/* affected rows related */
35:     
try {
36:
37:         
exec_and_count(2$db'DROP TABLE IF EXISTS test'0);
38:         
exec_and_count(3$dbsprintf('CREATE TABLE test(id INT NOT NULL PRIMARY KEY, col1 CHAR(10)) ENGINE=%s'PDO_MYSQL_TEST_ENGINE), 0);
39:
40:         
$stmt $db->query("SHOW VARIABLES LIKE 'secure_file_priv'");
41:         if ((
$row $stmt->fetch(PDO::FETCH_ASSOC)) && ($row['value'] != '')) {
42:             
$filename $row['value'] . DIRECTORY_SEPARATOR  "pdo_mysql_exec_load_data.csv";
43:         } else {
44:             
$filename =  MySQLPDOTest::getTempDir() . DIRECTORY_SEPARATOR  "pdo_mysql_exec_load_data.csv";
45:         }
46:
47:         
$fp fopen($filename"w");
48:         
fwrite($fpb"1;foo\n");
49:         
fwrite($fpb"2;bar");
50:         
fclose($fp);
51:
52:         
$sql sprintf("LOAD DATA INFILE %s INTO TABLE test FIELDS TERMINATED BY ';' LINES TERMINATED  BY '\n'"$db->quote($filename));
53:
54:         if (
exec_and_count(4$db$sql2)) {
55:
56:             
$stmt $db->query('SELECT id, col1 FROM test ORDER BY id ASC');
57:             
$expected = array(array("id" => 1"col1" => "foo"), array("id" => 2"col1" => "bar"));
58:             
$ret $stmt->fetchAll(PDO::FETCH_ASSOC);
59:             foreach (
$expected as $offset => $exp) {
60:                 foreach (
$exp as $key => $value) {
61:                     if (
$ret[$offset][$key] != $value) {
62:                         
printf("Results seem wrong, check manually\n");
63:                         
var_dump($ret);
64:                         
var_dump($expected);
65:                         break 
2;
66:                     }
67:                 }
68:             }
69:         }
70:
71:         
unlink($filename);
72:
73:     } catch (
PDOException $e) {
74:         
printf("[001] %s, [%s] %s\n",
75:             
$e->getMessage(),
76:             
$db->errorCode(), implode(' '$db->errorInfo()));
77:     }
78:
79:     print 
"done!";
80:
?>
81:

Expected

done!

Output

Warning: PDO::exec(): SQLSTATE[28000]: Invalid authorization specification: 1045 Access denied for user 'phpqa'@'localhost' (using password: YES) in /var/php_gcov/PHP_5_3/ext/pdo_mysql/tests/pdo_mysql_exec_load_data.php on line 6
[004] Expecting '2'/integer got ''/boolean when running 'LOAD DATA INFILE '/tmp/pdo_mysql_exec_load_data.csv' INTO TABLE test FIELDS TERMINATED BY ';' LINES TERMINATED  BY '
'', [28000] 28000 1045 Access denied for user 'phpqa'@'localhost' (using password: YES)
done!

Diff

001+ Warning: PDO::exec(): SQLSTATE[28000]: Invalid authorization specification: 1045 Access denied for user 'phpqa'@'localhost' (using password: YES) in /var/php_gcov/PHP_5_3/ext/pdo_mysql/tests/pdo_mysql_exec_load_data.php on line 6
002+ [004] Expecting '2'/integer got ''/boolean when running 'LOAD DATA INFILE '/tmp/pdo_mysql_exec_load_data.csv' INTO TABLE test FIELDS TERMINATED BY ';' LINES TERMINATED  BY '
003+ '', [28000] 28000 1045 Access denied for user 'phpqa'@'localhost' (using password: YES)

 

Generated at Fri, 18 Apr 2014 07:01:42 +0000 (5 days ago)

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