function bug_42499($db) {
$db->exec('DROP TABLE IF EXISTS test');
- $db->exec('CREATE TABLE test(id CHAR(1)); INSERT INTO test(id) VALUES ("a")');
+ $db->exec("CREATE TABLE test(id CHAR(1)); INSERT INTO test(id) VALUES ('a')");
$stmt = $db->query('SELECT id AS _id FROM test');
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
// You must not use exec() to run statements that create a result set!
$db->exec('SELECT id FROM test');
// This will bail at you because you have not fetched the SELECT results: this is not a bug!
- $db->exec('INSERT INTO test(id) VALUES ("b")');
+ $db->exec("INSERT INTO test(id) VALUES ('b')");
}
$db->exec('DROP TABLE IF EXISTS test');
$db->exec('CREATE TABLE test(id CHAR(1))');
- $db->exec('INSERT INTO test(id) VALUES ("a")');
- $stmt = $db->prepare('UPDATE test SET id = "b"');
+ $db->exec("INSERT INTO test(id) VALUES ('a')");
+ $stmt = $db->prepare("UPDATE test SET id = 'b'");
$stmt->execute();
- $stmt = $db->prepare('UPDATE test SET id = "c"');
+ $stmt = $db->prepare("UPDATE test SET id = 'c'");
$stmt->execute();
$stmt = $db->prepare('SELECT id FROM test');
$stmt->execute();
$db->exec('DROP TABLE IF EXISTS test');
$db->exec('CREATE TABLE test(id INT, label CHAR(1), PRIMARY KEY(id)) ENGINE=' . $engine);
- $db->exec('INSERT INTO test(id, label) VALUES (1, "a"), (2, "b"), (3, "c"), (4, "d"), (5, "e"), (6, "f")');
+ $db->exec("INSERT INTO test(id, label) VALUES (1, 'a'), (2, 'b'), (3, 'c'), (4, 'd'), (5, 'e'), (6, 'f')");
}
static function getTableEngine() {
}
static function dropTestTable($db = NULL) {
- if (is_null($db))
+ if (is_null($db))
$db = self::factory();
$db->exec('DROP TABLE IF EXISTS test');
$row = $db->query('SELECT COUNT(*) AS _num FROM test')->fetch(PDO::FETCH_ASSOC);
$num = $row['_num'];
- $db->query('INSERT INTO test(id, label) VALUES (100, "z")');
+ $db->query("INSERT INTO test(id, label) VALUES (100, 'z')");
$num++;
$row = $db->query('SELECT COUNT(*) AS _num FROM test')->fetch(PDO::FETCH_ASSOC);
if ($row['_num'] != $num)
var_dump($known[$default]);
// lets see what the default is...
- if (!is_object($stmt = $db->query('SELECT id, id AS "ID_UPPER", label FROM test ORDER BY id ASC LIMIT 2')))
+ if (!is_object($stmt = $db->query("SELECT id, id AS 'ID_UPPER', label FROM test ORDER BY id ASC LIMIT 2")))
printf("[002] %s - %s\n",
var_export($db->errorInfo(), true), var_export($db->errorCode(), true));
printf("[006] Cannot add column %s - %s\n",
var_export($db->errorInfo(), true), var_export($db->errorCode(), true));
- if (!is_object($stmt = $db->query('SELECT id, id AS "ID_UPPER", label, MiXeD, MYUPPER FROM test ORDER BY id ASC LIMIT 2')))
+ if (!is_object($stmt = $db->query("SELECT id, id AS 'ID_UPPER', label, MiXeD, MYUPPER FROM test ORDER BY id ASC LIMIT 2")))
printf("[007] %s - %s\n",
var_export($db->errorInfo(), true), var_export($db->errorCode(), true));
printf("[009] getAttribute(PDO::ATTR_CASE) returns wrong value '%s'\n",
var_export($tmp, true));
- if (!is_object($stmt = $db->query('SELECT id, label, MiXeD, MYUPPER, MYUPPER AS "lower" FROM test ORDER BY id ASC LIMIT 1')))
+ if (!is_object($stmt = $db->query("SELECT id, label, MiXeD, MYUPPER, MYUPPER AS 'lower' FROM test ORDER BY id ASC LIMIT 1")))
printf("[010] %s - %s\n",
var_export($db->errorInfo(), true), var_export($db->errorCode(), true));
printf("[012] getAttribute(PDO::ATTR_CASE) returns wrong value '%s'\n",
var_export($tmp, true));
- if (!is_object($stmt = $db->query('SELECT id, label, MiXeD, MYUPPER, id AS "ID" FROM test ORDER BY id ASC LIMIT 1')))
+ if (!is_object($stmt = $db->query("SELECT id, label, MiXeD, MYUPPER, id AS 'ID' FROM test ORDER BY id ASC LIMIT 1")))
printf("[013] %s - %s\n",
var_export($db->errorInfo(), true), var_export($db->errorCode(), true));
var_dump($stmt->fetchAll(PDO::FETCH_BOTH));
-
+
print "done!";
?>
--CLEAN--
printf("[003] Maybe PDO could indicate that this is not a proper way of setting ATTR_ORACLE_NULLS...\n");
$db->setAttribute(PDO::ATTR_ORACLE_NULLS, 1);
- $stmt = $db->query('SELECT NULL AS z, "" AS a, " " AS b, TRIM(" ") as c, " d" AS d, "' . chr(0) . ' e" AS e');
+ $stmt = $db->query("SELECT NULL AS z, '' AS a, ' ' AS b, TRIM(' ') as c, ' d' AS d, '" . chr(0) . " e' AS e");
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
$db->setAttribute(PDO::ATTR_ORACLE_NULLS, 0);
- $stmt = $db->query('SELECT NULL AS z, "" AS a, " " AS b, TRIM(" ") as c, " d" AS d, "' . chr(0) . ' e" AS e');
+ $stmt = $db->query("SELECT NULL AS z, '' AS a, ' ' AS b, TRIM(' ') as c, ' d' AS d, '" . chr(0) . " e' AS e");
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
$db->setAttribute(PDO::ATTR_ORACLE_NULLS, 1);
$db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
if ($have_procedures && (false !== $db->exec('DROP PROCEDURE IF EXISTS p')) &&
- (false !== $db->exec('CREATE PROCEDURE p() BEGIN SELECT NULL as z, "" AS a, " " AS b, TRIM(" ") as c, " d" AS d, " e" AS e; END;'))) {
+ (false !== $db->exec("CREATE PROCEDURE p() BEGIN SELECT NULL as z, '' AS a, ' ' AS b, TRIM(' ') as c, ' d' AS d, ' e' AS e; END;"))) {
// requires MySQL 5+
$stmt = $db->prepare('CALL p()');
$stmt->execute();
printf("[003] Did we change it from '%s' to '%s'?\n", $info, $info);
// lets hope we always run this in the same second as we did run the server info request...
- if (!$stmt = $db->query('SHOW STATUS LIKE "%uptime%"'))
+ if (!$stmt = $db->query("SHOW STATUS LIKE '%uptime%'"))
printf("[004] Cannot run SHOW STATUS, [%s]\n", $db->errorCode());
else {
if (!$row = $stmt->fetch(PDO::FETCH_NUM))
if (!$db->beginTransaction())
printf("[011] [%s] %s\n", $db->errorCode(), implode(' ', $db->errorInfo()));
- $db->exec(sprintf('INSERT INTO test(id, label) VALUES (%d, "z")', $row['id']));
+ $db->exec(sprintf("INSERT INTO test(id, label) VALUES (%d, 'z')", $row['id']));
if (!($stmt = $db->query(sprintf('SELECT id, label FROM test WHERE id = %d', $row['id']))))
printf("[012] [%s] %s\n", $db->errorCode(), implode(' ', $db->errorInfo()));
printf("[035] Cannot start a transaction, [%s] [%s]\n",
$db->errorCode(), implode(' ', $db->errorInfo()));
- if (0 == $db->exec('INSERT INTO test(id, label) VALUES (1, "a")'))
+ if (0 == $db->exec("INSERT INTO test(id, label) VALUES (1, 'a')"))
printf("[036] Cannot insert data, [%s] [%s]\n",
$db->errorCode(), implode(' ', $db->errorInfo()));
if (true !== ($tmp = $db->beginTransaction()))
printf("[004] Expecting true, got %s/%s\n", gettype($tmp), $tmp);
- $db->exec('INSERT INTO test(id, label) VALUES (100, "z")');
+ $db->exec("INSERT INTO test(id, label) VALUES (100, 'z')");
if (true !== ($tmp = $db->commit()))
printf("[005] No commit allowed? [%s] %s\n",
if (true !== ($tmp = $db->beginTransaction()))
printf("[007] Expecting true, got %s/%s\n", gettype($tmp), $tmp);
- $db->exec('INSERT INTO test(id, label) VALUES (100, "z")');
+ $db->exec("INSERT INTO test(id, label) VALUES (100, 'z')");
if (true !== ($tmp = $db->commit()))
printf("[008] No commit allowed? [%s] %s\n",
$db->errorCode(), implode(' ', $db->errorInfo()));
exec_and_count(2, $db, 'DROP TABLE IF EXISTS test', 0);
exec_and_count(3, $db, sprintf('CREATE TABLE test(id INT NOT NULL PRIMARY KEY, col1 CHAR(10)) ENGINE=%s', PDO_MYSQL_TEST_ENGINE), 0);
- exec_and_count(4, $db, 'INSERT INTO test(id, col1) VALUES (1, "a")', 1);
- exec_and_count(5, $db, 'INSERT INTO test(id, col1) VALUES (2, "b"), (3, "c")', 2);
- exec_and_count(6, $db, 'UPDATE test SET id = 4 WHERE id = 3', 1);
- exec_and_count(7, $db, 'INSERT INTO test(id, col1) VALUES (1, "d") ON DUPLICATE KEY UPDATE id = 3', 2);
- exec_and_count(8, $db, 'UPDATE test SET id = 5 WHERE id = 5', 0);
- exec_and_count(9, $db, 'INSERT INTO test(id, col1) VALUES (5, "e") ON DUPLICATE KEY UPDATE id = 6', 1);
- exec_and_count(10, $db, 'REPLACE INTO test(id, col1) VALUES (5, "f")', 2);
- exec_and_count(11, $db, 'REPLACE INTO test(id, col1) VALUES (6, "g")', 1);
+ exec_and_count(4, $db, "INSERT INTO test(id, col1) VALUES (1, 'a')", 1);
+ exec_and_count(5, $db, "INSERT INTO test(id, col1) VALUES (2, 'b'), (3, 'c')", 2);
+ exec_and_count(6, $db, "UPDATE test SET id = 4 WHERE id = 3", 1);
+ exec_and_count(7, $db, "INSERT INTO test(id, col1) VALUES (1, 'd') ON DUPLICATE KEY UPDATE id = 3", 2);
+ exec_and_count(8, $db, "UPDATE test SET id = 5 WHERE id = 5", 0);
+ exec_and_count(9, $db, "INSERT INTO test(id, col1) VALUES (5, 'e') ON DUPLICATE KEY UPDATE id = 6", 1);
+ exec_and_count(10, $db, "REPLACE INTO test(id, col1) VALUES (5, 'f')", 2);
+ exec_and_count(11, $db, "REPLACE INTO test(id, col1) VALUES (6, 'g')", 1);
exec_and_count(12, $db, 'DELETE FROM test WHERE id > 2', 4);
exec_and_count(13, $db, 'DROP TABLE test', 0);
exec_and_count(14, $db, 'SET @myvar = 1', 0);
printf("[016] [%s] %s\n", $db->errorCode(), implode(' ', $db->errorInfo()));
exec_and_count(36, $db, sprintf('CREATE TABLE test(id INT NOT NULL PRIMARY KEY, col1 CHAR(10)) ENGINE=%s', PDO_MYSQL_TEST_ENGINE), 0);
- exec_and_count(37, $db, 'INSERT INTO test(id, col1) VALUES (1, "a")', 1);
+ exec_and_count(37, $db, "INSERT INTO test(id, col1) VALUES (1, 'a')", 1);
// Results may vary. Typically you will get 1. But the MySQL 5.1 manual states: Truncation operations do not return the number of deleted rows.
// Don't rely on any return value!
exec_and_count(38, $db, 'TRUNCATE TABLE test', NULL);
exec_and_count(2, $db, 'DROP TABLE IF EXISTS test', 0);
exec_and_count(3, $db, sprintf('CREATE TABLE test(id INT NOT NULL PRIMARY KEY, col1 CHAR(10)) ENGINE=%s', PDO_MYSQL_TEST_ENGINE), 0);
- $stmt = $db->query('SHOW VARIABLES LIKE "secure_file_priv"');
+ $stmt = $db->query("SHOW VARIABLES LIKE 'secure_file_priv'");
if (($row = $stmt->fetch(PDO::FETCH_ASSOC)) && ($row['value'] != '')) {
$filename = $row['value'] . DIRECTORY_SEPARATOR . "pdo_mysql_exec_load_data.csv";
} else {
exec_and_count(2, $db, 'DROP TABLE IF EXISTS test', 0);
exec_and_count(3, $db, sprintf('CREATE TABLE test(id INT NOT NULL PRIMARY KEY, col1 CHAR(10)) ENGINE=%s', PDO_MYSQL_TEST_ENGINE), 0);
- exec_and_count(4, $db, 'INSERT INTO test(id, col1) VALUES (1, "a")', 1);
+ exec_and_count(4, $db, "INSERT INTO test(id, col1) VALUES (1, 'a')", 1);
// question is: will the result set be cleaned up, will it be possible to run more queries on the line?
// buffered or unbuffered does not matter!
$db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
exec_and_count(5, $db, 'SELECT id FROM test', 0);
- exec_and_count(6, $db, 'INSERT INTO test(id, col1) VALUES (2, "b")', 1);
+ exec_and_count(6, $db, "INSERT INTO test(id, col1) VALUES (2, 'b')", 1);
} catch (PDOException $e) {
printf("[001] %s, [%s] %s\n",
$e->getMessage(),
$db->errorCode(), implode(' ', $db->errorInfo()));
}
-
+
print "done!";
?>
--CLEAN--
?>
--EXPECTF--
Warning: PDO::exec(): SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active. Consider using PDOStatement::fetchAll(). Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute. in %s on line %d
-[006] Expecting '1'/integer got ''/boolean when running 'INSERT INTO test(id, col1) VALUES (2, "b")', [HY000] HY000 2014 Cannot execute queries while other unbuffered queries are active. Consider using PDOStatement::fetchAll(). Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute.
+[006] Expecting '1'/integer got ''/boolean when running 'INSERT INTO test(id, col1) VALUES (2, 'b')', [HY000] HY000 2014 Cannot execute queries while other unbuffered queries are active. Consider using PDOStatement::fetchAll(). Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute.
done!
\ No newline at end of file
printf("[005] Expecting '0'/string got '%s'/%s", var_export($tmp, true), gettype($tmp));
// no auto increment column
- $db->exec('INSERT INTO test(id, col1) VALUES (100, "a")');
+ $db->exec("INSERT INTO test(id, col1) VALUES (100, 'a')");
if ('0' !== ($tmp = $db->lastInsertId()))
printf("[006] Expecting '0'/string got '%s'/%s", var_export($tmp, true), gettype($tmp));
printf("[006] Expecting '0'/string got '%s'/%s", var_export($tmp, true), gettype($tmp));
// duplicate key
- @$db->exec('INSERT INTO test(id, col1) VALUES (100, "a")');
+ @$db->exec("INSERT INTO test(id, col1) VALUES (100, 'a')");
if ('0' !== ($tmp = $db->lastInsertId()))
printf("[007] Expecting '0'/string got '%s'/%s", var_export($tmp, true), gettype($tmp));
- $db->exec('INSERT INTO test(id, col1) VALUES (101, "b")');
+ $db->exec("INSERT INTO test(id, col1) VALUES (101, 'b')");
if ('101' !== ($tmp = $db->lastInsertId()))
printf("[008] Expecting '0'/string got '%s'/%s", var_export($tmp, true), gettype($tmp));
$db->exec('ALTER TABLE test MODIFY col1 CHAR(10) UNIQUE');
// replace = delete + insert -> new auto increment value
- $db->exec('REPLACE INTO test(col1) VALUES ("b")');
+ $db->exec("REPLACE INTO test(col1) VALUES ('b')");
$next_id = (int)$db->lastInsertId();
if ($next_id <= 101)
$last_id, $next_id);
}
- $db->exec('INSERT INTO test(col1) VALUES ("c"), ("d"), ("e")');
+ $db->exec("INSERT INTO test(col1) VALUES ('c'), ('d'), ('e')");
$next_id = (int)$db->lastInsertId();
if ($next_id <= $last_id)
printf("[011] Expecting at least %d, got %d\n", $last_id + 1, $next_id);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$last_id = $row['_last_id'];
- $db->exec('INSERT INTO test(col1) VALUES ("z")');
+ $db->exec("INSERT INTO test(col1) VALUES ('z')");
$next_id = (int)$db->lastInsertId();
if ($next_id < ($last_id + $inc))
printf("[012] Expecting at least %d, got %d\n", $last_id + $inc, $next_id);
prepex(5, $db, 'DROP TABLE IF EXISTS test');
prepex(6, $db, sprintf('CREATE TABLE test(id INT, label CHAR(255)) ENGINE=%s', PDO_MYSQL_TEST_ENGINE));
- prepex(7, $db, 'INSERT INTO test(id, label) VALUES(1, ":placeholder")');
+ prepex(7, $db, "INSERT INTO test(id, label) VALUES(1, ':placeholder')");
$stmt = prepex(8, $db, 'SELECT label FROM test');
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
prepex(9, $db, 'DELETE FROM test');
- prepex(10, $db, 'INSERT INTO test(id, label) VALUES(1, ":placeholder")',
+ prepex(10, $db, "INSERT INTO test(id, label) VALUES(1, ':placeholder')",
array(':placeholder' => 'first row'));
$stmt = prepex(11, $db, 'SELECT label FROM test');
// and now, the same with anonymous placeholders...
prepex(45, $db, 'DROP TABLE IF EXISTS test');
prepex(46, $db, sprintf('CREATE TABLE test(id INT, label CHAR(255)) ENGINE=%s', PDO_MYSQL_TEST_ENGINE));
- prepex(47, $db, 'INSERT INTO test(id, label) VALUES(1, "?")');
+ prepex(47, $db, "INSERT INTO test(id, label) VALUES(1, '?')");
$stmt = prepex(48, $db, 'SELECT label FROM test');
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
prepex(49, $db, 'DELETE FROM test');
- prepex(50, $db, 'INSERT INTO test(id, label) VALUES(1, "?")',
+ prepex(50, $db, "INSERT INTO test(id, label) VALUES(1, '?')",
array('first row'));
$stmt = prepex(51, $db, 'SELECT label FROM test');
$db->exec('DROP TABLE IF EXISTS test');
$db->exec(sprintf('CREATE TABLE test(id INT, label CHAR(255)) ENGINE=%s', PDO_MYSQL_TEST_ENGINE));
- $stmt = $db->prepare('INSERT INTO test(id, label) VALUES(1, "?")');
+ $stmt = $db->prepare("INSERT INTO test(id, label) VALUES(1, '?')");
// you can bind as many values as you want no matter if they can be replaced or not
$stmt->execute(array('first row'));
if ('00000' !== $stmt->errorCode())
printf("[004] Unable to switch off emulated prepared statements, test will fail\n");
$db->exec('DELETE FROM test');
- $stmt = $db->prepare('INSERT INTO test(id, label) VALUES(1, "?")');
+ $stmt = $db->prepare("INSERT INTO test(id, label) VALUES(1, '?')");
// you can bind as many values as you want no matter if they can be replaced or not
$stmt->execute(array('first row'));
if ('00000' !== $stmt->errorCode())
$db->exec('DROP TABLE IF EXISTS test');
$db->exec(sprintf('CREATE TABLE test(id INT, label CHAR(255)) ENGINE=%s', PDO_MYSQL_TEST_ENGINE));
- $db->exec('INSERT INTO test(id, label) VALUES (1, "row1")');
+ $db->exec("INSERT INTO test(id, label) VALUES (1, 'row1')");
// So, what will happen? More placeholder but values and
// placeholders in interesting places...
exec_and_count(2, $db, 'DROP TABLE IF EXISTS test', 0);
exec_and_count(3, $db, sprintf('CREATE TABLE test(id INT NOT NULL PRIMARY KEY, col1 CHAR(10)) ENGINE=%s', PDO_MYSQL_TEST_ENGINE), 0);
- $stmt = $db->query('SHOW VARIABLES LIKE "secure_file_priv"');
+ $stmt = $db->query("SHOW VARIABLES LIKE 'secure_file_priv'");
if (($row = $stmt->fetch(PDO::FETCH_ASSOC)) && ($row['value'] != '')) {
$filename = $row['value'] . DIRECTORY_SEPARATOR . "pdo_mysql_exec_load_data.csv";
} else {
}
// Check the line
- $stmt = $db->query('SELECT 1 as "one"');
+ $stmt = $db->query("SELECT 1 as 'one'");
if ($stmt->errorCode() != '0000') {
printf("[005] [%d] %s\n", $stmt->errorCode(), var_export($stmt->errorInfo(), true));
} else {
implode(' ', $db->errorInfo()),
(isset($stmt)) ? implode(' ', $stmt->errorInfo()) : 'N/A');
}
-
+
print "done!";
?>
--CLEAN--
prepex(5, $db, 'DROP TABLE IF EXISTS test');
prepex(6, $db, sprintf('CREATE TABLE test(id INT, label CHAR(255)) ENGINE=%s', PDO_MYSQL_TEST_ENGINE));
- prepex(7, $db, 'INSERT INTO test(id, label) VALUES(1, ":placeholder")');
+ prepex(7, $db, "INSERT INTO test(id, label) VALUES(1, ':placeholder')");
$stmt = prepex(8, $db, 'SELECT label FROM test ORDER BY id ASC');
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
}
$db->exec('DELETE FROM test');
- $db->exec('INSERT INTO test(id, label) VALUES (1, "row1")');
- $db->exec('INSERT INTO test(id, label) VALUES (2, "row2")');
+ $db->exec("INSERT INTO test(id, label) VALUES (1, 'row1')");
+ $db->exec("INSERT INTO test(id, label) VALUES (2, 'row2')");
$sql = sprintf("SELECT id, label FROM test WHERE (label LIKE %s) AND (id = :placeholder)",
$db->quote('%ro%'));
// and now, the same with anonymous placeholders...
prepex(33, $db, 'DROP TABLE IF EXISTS test');
prepex(34, $db, sprintf('CREATE TABLE test(id INT, label CHAR(255)) ENGINE=%s', PDO_MYSQL_TEST_ENGINE));
- prepex(35, $db, 'INSERT INTO test(id, label) VALUES(1, "?")');
+ prepex(35, $db, "INSERT INTO test(id, label) VALUES(1, '?')");
$stmt = prepex(36, $db, 'SELECT label FROM test');
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
printf("[002] Unable to turn on emulated prepared statements\n");
// INSERT a single row
- $db->exec('INSERT INTO test(id, label) VALUES (1, "row1")');
+ $db->exec("INSERT INTO test(id, label) VALUES (1, 'row1')");
$stmt = $db->prepare('SELECT unknown_column FROM test WHERE id > :placeholder ORDER BY id ASC');
$stmt->execute(array(':placeholder' => 0));
//
$db->exec('DELETE FROM test');
- $db->exec('INSERT INTO test (id, label1, label2) VALUES (1, "row1", "row2")');
+ $db->exec("INSERT INTO test (id, label1, label2) VALUES (1, 'row1', 'row2')");
$sql = "SELECT id, label1 FROM test WHERE id = :placeholder AND label1 = (SELECT label1 AS 'SELECT' FROM test WHERE id = :placeholder)";
// emulated...
printf("[002] Unable to turn off emulated prepared statements\n");
// INSERT a single row
- $stmt = $db->prepare('INSERT INTO test(id, label) VALUES (100, ":placeholder")');
+ $stmt = $db->prepare("INSERT INTO test(id, label) VALUES (100, ':placeholder')");
// Yes, there is no placeholder to bind to and named placeholder
// do not work with MySQL native PS, but lets see what happens!
printf("[004] Unable to turn on emulated prepared statements\n");
// Note that the "named placeholder" is enclosed by double quotes.
- $stmt = $db->prepare('INSERT INTO test(id, label) VALUES(101, ":placeholder")');
+ $stmt = $db->prepare("INSERT INTO test(id, label) VALUES(101, ':placeholder')");
// No replacement shall be made
$stmt->execute(array(':placeholder' => 'row1'));
// Again, I'd like to see an error message
$db->exec('DROP TABLE IF EXISTS test');
$db->exec(sprintf('CREATE TABLE test(id INT, label CHAR(255)) ENGINE=%s', PDO_MYSQL_TEST_ENGINE));
- $db->exec('INSERT INTO test(id, label) VALUES (1, "row1")');
+ $db->exec("INSERT INTO test(id, label) VALUES (1, 'row1')");
$stmt = $db->prepare('SELECT ?, id, label FROM test WHERE ? = ? ORDER BY id ASC');
$stmt->execute(array('id', 'label', 'label'));
$row = $db->query('SELECT COUNT(*) AS _num FROM test')->fetch(PDO::FETCH_ASSOC);
$num = $row['_num'];
- $db->query('INSERT INTO test(id, label) VALUES (100, "z")');
+ $db->query("INSERT INTO test(id, label) VALUES (100, 'z')");
$num++;
$row = $db->query('SELECT COUNT(*) AS _num FROM test')->fetch(PDO::FETCH_ASSOC);
if ($row['_num'] != $num)
printf("[002] ROLLBACK has failed\n");
$db->beginTransaction();
- $db->query('INSERT INTO test(id, label) VALUES (100, "z")');
+ $db->query("INSERT INTO test(id, label) VALUES (100, 'z')");
$db->query('DROP TABLE IF EXISTS test2');
$db->query('CREATE TABLE test2(id INT)');
$num++;
if (1 != $db->getAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY))
printf("[002] Unable to turn on emulated prepared statements\n");
- $stmt = $db->prepare('SELECT id, label, "?" as foo FROM test');
+ $stmt = $db->prepare("SELECT id, label, '?' as foo FROM test");
$stmt->execute();
var_dump($stmt->columnCount());
if (0 != $db->getAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY))
printf("[004] Unable to turn off emulated prepared statements\n");
- $stmt = $db->prepare('SELECT id, label, "?" as foo, "TODO - Stored Procedure" as bar FROM test');
+ $stmt = $db->prepare("SELECT id, label, '?' as foo, 'TODO - Stored Procedure' as bar FROM test");
$stmt->execute();
var_dump($stmt->columnCount());
printf("[011] Unable to turn off emulated prepared statements\n");
$native_support = 'no';
- if ($db->exec('PREPARE mystmt FROM "DESCRIBE test id"')) {
+ if ($db->exec("PREPARE mystmt FROM 'DESCRIBE test id'")) {
$native_support = 'yes';
$db->exec('DEALLOCATE PREPARE mystmt');
}
$native_support = 'no';
- if ($db->exec('PREPARE mystmt FROM "SHOW ENGINES"')) {
+ if ($db->exec("PREPARE mystmt FROM 'SHOW ENGINES'")) {
$native_support = 'yes';
$db->exec('DEALLOCATE PREPARE mystmt');
}
var_export($show_native, true));
$native_support = 'no';
- if ($db->exec('PREPARE mystmt FROM "EXPLAIN SELECT id FROM test"')) {
+ if ($db->exec("PREPARE mystmt FROM 'EXPLAIN SELECT id FROM test'")) {
$native_support = 'yes';
$db->exec('DEALLOCATE PREPARE mystmt');
}
printf("\nAnd now magic PDO using fetchAll(PDO::FETCH_CLASS|PDO::FETCH_SERIALIZE)...\n");
$db->exec('DROP TABLE IF EXISTS test');
$db->exec(sprintf('CREATE TABLE test(myobj BLOB) ENGINE=%s', MySQLPDOTest::getTableEngine()));
- $db->exec('INSERT INTO test(myobj) VALUES ("Data fetched from DB to be given to unserialize()")');
+ $db->exec("INSERT INTO test(myobj) VALUES ('Data fetched from DB to be given to unserialize()')");
$stmt = $db->prepare('SELECT myobj FROM test');
$stmt->execute();
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
MySQLPDOTest::skip();
$db = MySQLPDOTest::factory();
+
+try {
+ $query = "SELECT '', NULL, \"\" FROM DUAL";
+ $stmt = $db->prepare($query);
+ $ok = @$stmt->execute();
+} catch (PDOException $e) {
+ die("skip: Test cannot be run with SQL mode ANSI");
+}
+if (!$ok)
+ die("skip: Test cannot be run with SQL mode ANSI");
?>
--FILE--
<?php
try {
- // default settings
$query = "SELECT id, '', NULL, \"\" FROM test ORDER BY id ASC LIMIT 3";
$stmt = $db->prepare($query);
$this->not_a_magic_one();
printf("myclass::__set(%s, -%s-) %d\n",
$prop, var_export($value, true), $this->set_calls, self::$static_set_calls);
- if ("" != $prop)
+ if ("" != $prop)
$this->{$prop} = $value;
}
return true;
}
- if (!$db->exec(sprintf('INSERT INTO test(id, label) VALUES (1, "%s")', $value))) {
+ if (!$db->exec(sprintf("INSERT INTO test(id, label) VALUES (1, '%s')", $value))) {
printf("[%03d] + 1] Insert failed, %d - %s\n", $offset,
$db->errorCode(), var_export($db->errorInfo(), true));
return false;
return true;
}
+ $stmt = $db->prepare('SELECT @@sql_mode AS _mode');
+ $stmt->execute();
+ $row = $stmt->fetch(PDO::FETCH_ASSOC);
+ $real_as_float = (false === stristr($row['_mode'], "REAL_AS_FLOAT")) ? false : true;
+
$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
$is_mysqlnd = MySQLPDOTest::isPDOMySQLnd();
test_meta($db, 20, 'BIT(8)', 1, NULL, ($is_mysqlnd) ? PDO::PARAM_INT : PDO::PARAM_STR);
test_meta($db, 120, 'BIGINT', -9223372036854775808, 'LONGLONG', ($is_mysqlnd) ? ((PHP_INT_SIZE == 4) ? PDO::PARAM_STR : PDO::PARAM_INT) : PDO::PARAM_STR);
test_meta($db, 130, 'BIGINT UNSIGNED', 18446744073709551615, 'LONGLONG', ($is_mysqlnd) ? ((PHP_INT_SIZE == 4) ? PDO::PARAM_STR : PDO::PARAM_INT) : PDO::PARAM_STR);
- test_meta($db, 130, 'REAL', -1.01, 'DOUBLE', PDO::PARAM_STR);
- test_meta($db, 140, 'REAL UNSIGNED', 1.01, 'DOUBLE', PDO::PARAM_STR);
- test_meta($db, 150, 'REAL ZEROFILL', -1.01, 'DOUBLE', PDO::PARAM_STR);
- test_meta($db, 160, 'REAL UNSIGNED ZEROFILL', 1.01, 'DOUBLE', PDO::PARAM_STR);
+ test_meta($db, 130, 'REAL', -1.01, ($real_as_float) ? 'FLOAT' : 'DOUBLE', PDO::PARAM_STR);
+ test_meta($db, 140, 'REAL UNSIGNED', 1.01, ($real_as_float) ? 'FLOAT' : 'DOUBLE', PDO::PARAM_STR);
+ test_meta($db, 150, 'REAL ZEROFILL', -1.01, ($real_as_float) ? 'FLOAT' : 'DOUBLE', PDO::PARAM_STR);
+ test_meta($db, 160, 'REAL UNSIGNED ZEROFILL', 1.01, ($real_as_float) ? 'FLOAT' : 'DOUBLE', PDO::PARAM_STR);
test_meta($db, 170, 'DOUBLE', -1.01, 'DOUBLE', PDO::PARAM_STR);
test_meta($db, 180, 'DOUBLE UNSIGNED', 1.01, 'DOUBLE', PDO::PARAM_STR);
test_type($db, 80, 'MEDIUMINT', -8388608, ($is_mysqlnd) ? -8388608 : '-8388608');
test_type($db, 90, 'MEDIUMINT UNSIGNED', 16777215, ($is_mysqlnd) ? 16777215 : '16777215');
- test_type($db, 100, 'INT', -2147483648,
- ($is_mysqlnd) ? ((PHP_INT_SIZE > 4) ? (int)-2147483648 : (double)-2147483648) : '-2147483648',
+ test_type($db, 100, 'INT', -2147483648,
+ ($is_mysqlnd) ? ((PHP_INT_SIZE > 4) ? (int)-2147483648 : (double)-2147483648) : '-2147483648',
NULL, ($is_mysqlnd) ? 'integer' : NULL);
test_type($db, 110, 'INT UNSIGNED', 4294967295, ($is_mysqlnd) ? ((PHP_INT_SIZE > 4) ? 4294967295 : '4294967295') : '4294967295');
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
+ $stmt = $db->prepare('SELECT @@sql_mode AS _mode');
+ $stmt->execute();
+ $row = $stmt->fetch(PDO::FETCH_ASSOC);
+ $real_as_float = (false === stristr($row['_mode'], "REAL_AS_FLOAT")) ? false : true;
+
test_type($db, 100, 'REAL ZEROFILL', -1.01, NULL, '/^[0]*0$/');
- test_type($db, 110, 'REAL ZEROFILL', 1.01, NULL, '/^[0]*1\.01$/');
- test_type($db, 120, 'REAL UNSIGNED ZEROFILL', 1.01, NULL, '/^[0]*1\.01$/');
+ test_type($db, 110, 'REAL ZEROFILL', 1.01, NULL, ($real_as_float) ? '/^[0]*1\.0.*$/' : '/^[0]*1\.01$/');
+ test_type($db, 120, 'REAL UNSIGNED ZEROFILL', 1.01, NULL, ($real_as_float) ? '/^[0]*1\..*$/' : '/^[0]*1\.01$/');
test_type($db, 130, 'DOUBLE ZEROFILL', -1.01, NULL, '/^[0]*0$/');
test_type($db, 140, 'DOUBLE ZEROFILL', 1.01, NULL, '/^[0]*1\.01$/');