import zend pdo_mysql tests
I did some minor surgery to the import script to always copy in the php files. This is because zend has ##config.phpt## files which, as their name doens't reveal, aren't really tests but instead are config files. After all that, the tests still didn't work because I'm not running mysql on localhost.
Esse commit está contido em:
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
|
||||
|
||||
$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
|
||||
|
||||
$search = "o'";
|
||||
$sql = "SELECT 1 FROM DUAL WHERE 'o''riley' LIKE " . $db->quote('%' . $search . '%');
|
||||
$stmt = $db->prepare($sql);
|
||||
$stmt->execute();
|
||||
print implode(' - ', (($r = @$stmt->fetch(PDO::FETCH_NUM)) ? $r : array())) ."\n";
|
||||
print implode(' - ', $stmt->errorinfo()) ."\n";
|
||||
|
||||
print "-------------------------------------------------------\n";
|
||||
|
||||
$queries = array(
|
||||
"SELECT 1 FROM DUAL WHERE 1 = '?\'\''",
|
||||
"SELECT 'a\\'0' FROM DUAL WHERE 1 = ?",
|
||||
"SELECT 'a', 'b\'' FROM DUAL WHERE '''' LIKE '\\'' AND ?",
|
||||
"SELECT 'foo?bar', '', '''' FROM DUAL WHERE ?"
|
||||
);
|
||||
|
||||
foreach ($queries as $k => $query) {
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->execute(array(1));
|
||||
printf("[%d] Query: [[%s]]\n", $k + 1, $query);
|
||||
print implode(' - ', (($r = @$stmt->fetch(PDO::FETCH_NUM)) ? $r : array())) ."\n";
|
||||
print implode(' - ', $stmt->errorinfo()) ."\n";
|
||||
print "--------\n";
|
||||
}
|
||||
|
||||
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1);
|
||||
$sql = "SELECT upper(:id) FROM DUAL WHERE '1'";
|
||||
$stmt = $db->prepare($sql);
|
||||
|
||||
$id = 'o\'\0';
|
||||
$stmt->bindParam(':id', $id);
|
||||
$stmt->execute();
|
||||
printf("Query: [[%s]]\n", $sql);
|
||||
print implode(' - ', (($r = @$stmt->fetch(PDO::FETCH_NUM)) ? $r : array())) ."\n";
|
||||
print implode(' - ', $stmt->errorinfo()) ."\n";
|
||||
|
||||
print "-------------------------------------------------------\n";
|
||||
|
||||
$queries = array(
|
||||
"SELECT 1, 'foo' FROM DUAL WHERE 1 = :id AND '\\0' IS NULL AND 2 <> :id",
|
||||
"SELECT 1 FROM DUAL WHERE 1 = :id AND '' AND 2 <> :id",
|
||||
"SELECT 1 FROM DUAL WHERE 1 = :id AND '\'\'' = '''' AND 2 <> :id",
|
||||
"SELECT 1 FROM DUAL WHERE 1 = :id AND '\'' = '''' AND 2 <> :id",
|
||||
"SELECT 'a', 'b\'' FROM DUAL WHERE '''' LIKE '\\'' AND 1",
|
||||
"SELECT 'a''', '\'b\'' FROM DUAL WHERE '''' LIKE '\\'' AND 1",
|
||||
"SELECT UPPER(:id) FROM DUAL WHERE '1'",
|
||||
"SELECT 1 FROM DUAL WHERE '\''",
|
||||
"SELECT 1 FROM DUAL WHERE :id AND '\\0' OR :id",
|
||||
"SELECT 1 FROM DUAL WHERE 'a\\f\\n\\0' AND 1 >= :id",
|
||||
"SELECT 1 FROM DUAL WHERE '\'' = ''''",
|
||||
"SELECT '\\n' '1 FROM DUAL WHERE '''' and :id'",
|
||||
"SELECT 1 'FROM DUAL WHERE :id AND '''' = '''' OR 1 = 1 AND ':id",
|
||||
);
|
||||
|
||||
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1);
|
||||
$id = 1;
|
||||
|
||||
foreach ($queries as $k => $query) {
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->bindParam(':id', $id);
|
||||
$stmt->execute();
|
||||
|
||||
printf("[%d] Query: [[%s]]\n", $k + 1, $query);
|
||||
print implode(' - ', (($r = @$stmt->fetch(PDO::FETCH_NUM)) ? $r : array())) ."\n";
|
||||
print implode(' - ', $stmt->errorinfo()) ."\n";
|
||||
print "--------\n";
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,76 @@
|
||||
1
|
||||
00000 - -
|
||||
-------------------------------------------------------
|
||||
[1] Query: [[SELECT 1 FROM DUAL WHERE 1 = '?\'\'']]
|
||||
|
||||
00000 - -
|
||||
--------
|
||||
[2] Query: [[SELECT 'a\'0' FROM DUAL WHERE 1 = ?]]
|
||||
a'0
|
||||
00000 - -
|
||||
--------
|
||||
[3] Query: [[SELECT 'a', 'b\'' FROM DUAL WHERE '''' LIKE '\'' AND ?]]
|
||||
a - b'
|
||||
00000 - -
|
||||
--------
|
||||
[4] Query: [[SELECT 'foo?bar', '', '''' FROM DUAL WHERE ?]]
|
||||
foo?bar - - '
|
||||
00000 - -
|
||||
--------
|
||||
Query: [[SELECT upper(:id) FROM DUAL WHERE '1']]
|
||||
O'\0
|
||||
00000 - -
|
||||
-------------------------------------------------------
|
||||
[1] Query: [[SELECT 1, 'foo' FROM DUAL WHERE 1 = :id AND '\0' IS NULL AND 2 <> :id]]
|
||||
|
||||
00000 - -
|
||||
--------
|
||||
[2] Query: [[SELECT 1 FROM DUAL WHERE 1 = :id AND '' AND 2 <> :id]]
|
||||
|
||||
00000 - -
|
||||
--------
|
||||
[3] Query: [[SELECT 1 FROM DUAL WHERE 1 = :id AND '\'\'' = '''' AND 2 <> :id]]
|
||||
|
||||
00000 - -
|
||||
--------
|
||||
[4] Query: [[SELECT 1 FROM DUAL WHERE 1 = :id AND '\'' = '''' AND 2 <> :id]]
|
||||
1
|
||||
00000 - -
|
||||
--------
|
||||
[5] Query: [[SELECT 'a', 'b\'' FROM DUAL WHERE '''' LIKE '\'' AND 1]]
|
||||
a - b'
|
||||
00000 - -
|
||||
--------
|
||||
[6] Query: [[SELECT 'a''', '\'b\'' FROM DUAL WHERE '''' LIKE '\'' AND 1]]
|
||||
a' - 'b'
|
||||
00000 - -
|
||||
--------
|
||||
[7] Query: [[SELECT UPPER(:id) FROM DUAL WHERE '1']]
|
||||
1
|
||||
00000 - -
|
||||
--------
|
||||
[8] Query: [[SELECT 1 FROM DUAL WHERE '\'']]
|
||||
|
||||
00000 - -
|
||||
--------
|
||||
[9] Query: [[SELECT 1 FROM DUAL WHERE :id AND '\0' OR :id]]
|
||||
1
|
||||
00000 - -
|
||||
--------
|
||||
[10] Query: [[SELECT 1 FROM DUAL WHERE 'a\f\n\0' AND 1 >= :id]]
|
||||
|
||||
00000 - -
|
||||
--------
|
||||
[11] Query: [[SELECT 1 FROM DUAL WHERE '\'' = '''']]
|
||||
1
|
||||
00000 - -
|
||||
--------
|
||||
[12] Query: [[SELECT '\n' '1 FROM DUAL WHERE '''' and :id']]
|
||||
|
||||
1 FROM DUAL WHERE '' and :id
|
||||
00000 - -
|
||||
--------
|
||||
[13] Query: [[SELECT 1 'FROM DUAL WHERE :id AND '''' = '''' OR 1 = 1 AND ':id]]
|
||||
1
|
||||
00000 - -
|
||||
--------
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
|
||||
$db = MySQLPDOTest::factory();
|
||||
|
||||
$stmt = $db->prepare("SELECT 1 AS \"one\"");
|
||||
$stmt->execute();
|
||||
$row = $stmt->fetch(PDO::FETCH_LAZY);
|
||||
var_dump($row);
|
||||
var_dump($row->{0});
|
||||
var_dump($row->one);
|
||||
var_dump($row->queryString);
|
||||
|
||||
print "----------------------------------\n";
|
||||
|
||||
@$db->exec("DROP TABLE test");
|
||||
$db->exec("CREATE TABLE test (id INT)");
|
||||
$db->exec("INSERT INTO test(id) VALUES (1)");
|
||||
$stmt = $db->prepare("SELECT id FROM test");
|
||||
$stmt->execute();
|
||||
$row = $stmt->fetch(PDO::FETCH_LAZY);
|
||||
var_dump($row);
|
||||
var_dump($row->queryString);
|
||||
@$db->exec("DROP TABLE test");
|
||||
|
||||
print "----------------------------------\n";
|
||||
|
||||
$stmt = $db->prepare('foo');
|
||||
@$stmt->execute();
|
||||
$row = $stmt->fetch();
|
||||
var_dump($row->queryString);
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,20 @@
|
||||
object(PDORow)#%d (2) {
|
||||
[%u|b%"queryString"]=>
|
||||
%unicode|string%(17) "SELECT 1 AS "one""
|
||||
[%u|b%"one"]=>
|
||||
%unicode|string%(1) "1"
|
||||
}
|
||||
%unicode|string%(1) "1"
|
||||
%unicode|string%(1) "1"
|
||||
%unicode|string%(17) "SELECT 1 AS "one""
|
||||
----------------------------------
|
||||
object(PDORow)#%d (2) {
|
||||
[%u|b%"queryString"]=>
|
||||
%unicode|string%(19) "SELECT id FROM test"
|
||||
[%u|b%"id"]=>
|
||||
%unicode|string%(1) "1"
|
||||
}
|
||||
%unicode|string%(19) "SELECT id FROM test"
|
||||
----------------------------------
|
||||
HipHop Notice: %a
|
||||
NULL
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
|
||||
$pdoDb = MySQLPDOTest::factory();
|
||||
|
||||
|
||||
class myclass implements Serializable {
|
||||
public function __construct() {
|
||||
printf("%s()\n", __METHOD__);
|
||||
}
|
||||
|
||||
public function serialize() {
|
||||
printf("%s()\n", __METHOD__);
|
||||
return "any data from serialize()";
|
||||
}
|
||||
|
||||
public function unserialize($dat) {
|
||||
printf("%s(%s)\n", __METHOD__, var_export($dat, true));
|
||||
return $dat;
|
||||
}
|
||||
}
|
||||
|
||||
class myclass2 extends myclass { }
|
||||
|
||||
$pdoDb->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
|
||||
$pdoDb->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
|
||||
|
||||
$pdoDb->query('DROP TABLE IF EXISTS testz');
|
||||
|
||||
$pdoDb->query('CREATE TABLE testz (name VARCHAR(20) NOT NULL, value INT)');
|
||||
|
||||
$pdoDb->query("INSERT INTO testz VALUES ('myclass', 1), ('myclass2', 2), ('myclass', NULL), ('myclass3', NULL)");
|
||||
|
||||
$stmt = $pdoDb->prepare("SELECT * FROM testz");
|
||||
|
||||
var_dump($stmt->setFetchMode(PDO::FETCH_CLASS | PDO::FETCH_CLASSTYPE | PDO::FETCH_GROUP));
|
||||
$stmt->execute();
|
||||
|
||||
var_dump($stmt->fetch());
|
||||
var_dump($stmt->fetch());
|
||||
var_dump($stmt->fetchAll());
|
||||
?><?php
|
||||
require dirname(__FILE__) . '/mysql_pdo_test.inc';
|
||||
$db = MySQLPDOTest::factory();
|
||||
$db->exec('DROP TABLE IF EXISTS testz');
|
||||
?>
|
||||
@@ -0,0 +1,24 @@
|
||||
bool(true)
|
||||
myclass::__construct()
|
||||
object(myclass)#%d (1) {
|
||||
[%u|b%"value"]=>
|
||||
%unicode|string%(1) "1"
|
||||
}
|
||||
myclass::__construct()
|
||||
object(myclass2)#%d (1) {
|
||||
[%u|b%"value"]=>
|
||||
%unicode|string%(1) "2"
|
||||
}
|
||||
myclass::__construct()
|
||||
array(2) {
|
||||
[0]=>
|
||||
object(myclass)#%d (1) {
|
||||
[%u|b%"value"]=>
|
||||
NULL
|
||||
}
|
||||
[1]=>
|
||||
object(stdClass)#%d (1) {
|
||||
[%u|b%"value"]=>
|
||||
NULL
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
include __DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc';
|
||||
$db = MySQLPDOTest::factory();
|
||||
|
||||
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0);
|
||||
|
||||
$createSql = "CREATE TABLE `bug53551` (
|
||||
`count` bigint(20) unsigned NOT NULL DEFAULT '0'
|
||||
)";
|
||||
|
||||
$db->exec('drop table if exists bug53551');
|
||||
$db->exec($createSql);
|
||||
$db->exec("insert into bug53551 set `count` = 1 ");
|
||||
$db->exec("SET sql_mode = 'Traditional'");
|
||||
$sql = 'UPDATE bug53551 SET `count` = :count';
|
||||
$stmt = $db->prepare($sql);
|
||||
|
||||
$values = array (
|
||||
'count' => NULL,
|
||||
);
|
||||
|
||||
echo "1\n";
|
||||
$stmt->execute($values);
|
||||
var_dump($stmt->errorInfo());
|
||||
|
||||
echo "2\n";
|
||||
$stmt->execute($values);
|
||||
var_dump($stmt->errorInfo());
|
||||
|
||||
echo "\ndone\n";
|
||||
|
||||
?><?php
|
||||
include __DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc';
|
||||
$db = MySQLPDOTest::factory();
|
||||
$db->exec('DROP TABLE IF EXISTS bug53551');
|
||||
?>
|
||||
@@ -0,0 +1,22 @@
|
||||
1
|
||||
HipHop Warning: %a
|
||||
array(3) {
|
||||
[0]=>
|
||||
string(5) "23000"
|
||||
[1]=>
|
||||
int(1048)
|
||||
[2]=>
|
||||
string(29) "Column 'count' cannot be null"
|
||||
}
|
||||
2
|
||||
HipHop Warning: %a
|
||||
array(3) {
|
||||
[0]=>
|
||||
string(5) "23000"
|
||||
[1]=>
|
||||
int(1048)
|
||||
[2]=>
|
||||
string(29) "Column 'count' cannot be null"
|
||||
}
|
||||
|
||||
done
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
require dirname(__FILE__) . '/config.inc';
|
||||
require dirname(__FILE__) . '/../ext-pdo/pdo_test.inc';
|
||||
$conn = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
|
||||
|
||||
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
|
||||
$res = $conn->query('SELECT 0');
|
||||
|
||||
try {
|
||||
$conn->query('ERROR');
|
||||
} catch (PDOException $e) {
|
||||
echo "Caught: ".$e->getMessage()."\n";
|
||||
}
|
||||
|
||||
foreach ($res as $k => $v) {
|
||||
echo "Value: $v[0]\n";
|
||||
}
|
||||
|
||||
echo "DONE";
|
||||
?><?php
|
||||
require dirname(__FILE__) . '/mysql_pdo_test.inc';
|
||||
MySQLPDOTest::dropTestTable();
|
||||
?>
|
||||
@@ -0,0 +1,3 @@
|
||||
Caught: SQLSTATE[42000]: %s
|
||||
Value: 0
|
||||
DONE
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
|
||||
|
||||
$pdodb = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
|
||||
|
||||
|
||||
function testQuery($query) {
|
||||
global $pdodb;
|
||||
$stmt = $pdodb->prepare($query);
|
||||
|
||||
if (!$stmt->execute(array("foo"))) {
|
||||
var_dump($stmt->errorInfo());
|
||||
} else{
|
||||
var_dump($stmt->fetch(PDO::FETCH_ASSOC));
|
||||
}
|
||||
}
|
||||
|
||||
testQuery("/* ' */ select ? as f1 /* ' */");
|
||||
testQuery("/* '-- */ select ? as f1 /* *' */");
|
||||
testQuery("/* ' */ select ? as f1 --';");
|
||||
testQuery("/* ' */ select ? as f1 -- 'a;");
|
||||
testQuery("/*'**/ select ? as f1 /* ' */");
|
||||
testQuery("/*'***/ select ? as f1 /* ' */");
|
||||
testQuery("/*'**a ***b / ****
|
||||
******
|
||||
**/ select ? as f1 /* ' */");
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,33 @@
|
||||
array(1) {
|
||||
["f1"]=>
|
||||
string(3) "foo"
|
||||
}
|
||||
array(1) {
|
||||
["f1"]=>
|
||||
string(3) "foo"
|
||||
}
|
||||
HipHop Warning: %a
|
||||
array(3) {
|
||||
[0]=>
|
||||
string(5) "42000"
|
||||
[1]=>
|
||||
int(1064)
|
||||
[2]=>
|
||||
string(149) "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '--'' at line 1"
|
||||
}
|
||||
array(1) {
|
||||
["f1"]=>
|
||||
string(3) "foo"
|
||||
}
|
||||
array(1) {
|
||||
["f1"]=>
|
||||
string(3) "foo"
|
||||
}
|
||||
array(1) {
|
||||
["f1"]=>
|
||||
string(3) "foo"
|
||||
}
|
||||
array(1) {
|
||||
["f1"]=>
|
||||
string(3) "foo"
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
require dirname(__FILE__) . '/config.inc';
|
||||
require dirname(__FILE__) . '/../ext-pdo/pdo_test.inc';
|
||||
$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
|
||||
|
||||
$db->exec('CREATE TABLE test (bar INT NOT NULL)');
|
||||
$db->exec('INSERT INTO test VALUES(1)');
|
||||
|
||||
var_dump($db->query('SELECT * from test'));
|
||||
foreach ($db->query('SELECT * from test') as $row) {
|
||||
print_r($row);
|
||||
}
|
||||
|
||||
$stmt = $db->prepare('SELECT * from test');
|
||||
print_r($stmt->getColumnMeta(0));
|
||||
$stmt->execute();
|
||||
$tmp = $stmt->getColumnMeta(0);
|
||||
|
||||
// libmysql and mysqlnd will show the pdo_type entry at a different position in the hash
|
||||
if (!isset($tmp['pdo_type']) || (isset($tmp['pdo_type']) && $tmp['pdo_type'] != 2))
|
||||
printf("Expecting pdo_type = 2 got %s\n", $tmp['pdo_type']);
|
||||
else
|
||||
unset($tmp['pdo_type']);
|
||||
|
||||
print_r($tmp);
|
||||
?><?php
|
||||
require dirname(__FILE__) . '/mysql_pdo_test.inc';
|
||||
MySQLPDOTest::dropTestTable();
|
||||
?>
|
||||
@@ -0,0 +1,22 @@
|
||||
object(PDOStatement)#%d (1) {
|
||||
[%u|b%"queryString"]=>
|
||||
%unicode|string%(18) "SELECT * from test"
|
||||
}
|
||||
Array
|
||||
(
|
||||
[bar] => 1
|
||||
[0] => 1
|
||||
)
|
||||
Array
|
||||
(
|
||||
[native_type] => LONG
|
||||
[flags] => Array
|
||||
(
|
||||
[0] => not_null
|
||||
)
|
||||
|
||||
[table] => test
|
||||
[name] => bar
|
||||
[len] => 11
|
||||
[precision] => 0
|
||||
)
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
require dirname(__FILE__) . '/../ext-pdo/pdo_test.inc';
|
||||
$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
|
||||
|
||||
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, TRUE);
|
||||
$stmt = $db->prepare('SELECT UPPER(\'\0:D\0\'),?');
|
||||
$stmt->execute(array(1));
|
||||
var_dump($stmt->fetchAll(PDO::FETCH_NUM));
|
||||
Arquivo binário não exibido.
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
|
||||
$db = MySQLPDOTest::factory();
|
||||
$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
|
||||
|
||||
function bug_39858($db) {
|
||||
|
||||
$db->exec("DROP PROCEDURE IF EXISTS p");
|
||||
$db->exec("
|
||||
CREATE PROCEDURE p()
|
||||
NOT DETERMINISTIC
|
||||
CONTAINS SQL
|
||||
SQL SECURITY DEFINER
|
||||
COMMENT ''
|
||||
BEGIN
|
||||
SELECT 2 * 2;
|
||||
END;");
|
||||
|
||||
$stmt = $db->prepare("CALL p()");
|
||||
$stmt->execute();
|
||||
do {
|
||||
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
|
||||
} while ($stmt->nextRowset());
|
||||
|
||||
$stmt = $db->prepare("CALL p()");
|
||||
$stmt->execute();
|
||||
do {
|
||||
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
|
||||
} while ($stmt->nextRowset());
|
||||
$stmt->closeCursor();
|
||||
|
||||
}
|
||||
|
||||
printf("Emulated Prepared Statements...\n");
|
||||
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1);
|
||||
bug_39858($db);
|
||||
|
||||
printf("Native Prepared Statements...\n");
|
||||
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0);
|
||||
bug_39858($db);
|
||||
|
||||
print "done!";
|
||||
?><?php
|
||||
require dirname(__FILE__) . '/mysql_pdo_test.inc';
|
||||
$db = MySQLPDOTest::factory();
|
||||
$db->exec("DROP PROCEDURE IF EXISTS p");
|
||||
?>
|
||||
@@ -0,0 +1,31 @@
|
||||
Emulated Prepared Statements...
|
||||
array(1) {
|
||||
[0]=>
|
||||
array(1) {
|
||||
[%u|b%"2 * 2"]=>
|
||||
%unicode|string%(1) "4"
|
||||
}
|
||||
}
|
||||
array(1) {
|
||||
[0]=>
|
||||
array(1) {
|
||||
[%u|b%"2 * 2"]=>
|
||||
%unicode|string%(1) "4"
|
||||
}
|
||||
}
|
||||
Native Prepared Statements...
|
||||
array(1) {
|
||||
[0]=>
|
||||
array(1) {
|
||||
[%u|b%"2 * 2"]=>
|
||||
%unicode|string%(1) "4"
|
||||
}
|
||||
}
|
||||
array(1) {
|
||||
[0]=>
|
||||
array(1) {
|
||||
[%u|b%"2 * 2"]=>
|
||||
%unicode|string%(1) "4"
|
||||
}
|
||||
}
|
||||
done!
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
|
||||
$db = MySQLPDOTest::factory();
|
||||
$db->exec("DROP TABLE IF EXISTS test");
|
||||
|
||||
// And now allow the evil to do his work
|
||||
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1);
|
||||
$sql = "CREATE TABLE IF NOT EXISTS test(id INT); INSERT INTO test(id) VALUES (1); SELECT * FROM test; INSERT INTO test(id) VALUES (2); SELECT * FROM test;";
|
||||
// NOTE: This will fail, it is OK to fail - you must not mix DML/DDL and SELECT
|
||||
// The PDO API does not support multiple queries properly!
|
||||
// Read http://blog.ulf-wendel.de/?p=192
|
||||
// Compare MySQL C-API documentation
|
||||
$stmt = $db->query($sql);
|
||||
do {
|
||||
var_dump($stmt->fetchAll());
|
||||
} while ($stmt->nextRowset());
|
||||
|
||||
print "done!";
|
||||
?><?php
|
||||
require dirname(__FILE__) . '/mysql_pdo_test.inc';
|
||||
$db = MySQLPDOTest::factory();
|
||||
$db->exec("DROP TABLE IF EXISTS test");
|
||||
?>
|
||||
@@ -0,0 +1,4 @@
|
||||
HipHop Warning: %a
|
||||
array(0) {
|
||||
}
|
||||
done!
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
require dirname(__FILE__) . '/config.inc';
|
||||
require dirname(__FILE__) . '/../ext-pdo/pdo_test.inc';
|
||||
$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
|
||||
|
||||
setlocale(LC_ALL, "de","de_DE","de_DE.ISO8859-1","de_DE.ISO_8859-1","de_DE.UTF-8");
|
||||
|
||||
$db->exec('CREATE TABLE test(floatval DECIMAL(8,6))');
|
||||
$db->exec('INSERT INTO test VALUES(2.34)');
|
||||
$value=4.56;
|
||||
$stmt = $db->prepare('INSERT INTO test VALUES(?)');
|
||||
$stmt->execute(array($value));
|
||||
var_dump($db->query('SELECT * from test')->fetchAll(PDO::FETCH_ASSOC));
|
||||
?>
|
||||
@@ -0,0 +1,12 @@
|
||||
array(2) {
|
||||
[0]=>
|
||||
array(1) {
|
||||
[%u|b%"floatval"]=>
|
||||
%unicode|string%(8) "2.340000"
|
||||
}
|
||||
[1]=>
|
||||
array(1) {
|
||||
[%u|b%"floatval"]=>
|
||||
%unicode|string%(8) "4.560000"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
require dirname(__FILE__) . '/mysql_pdo_test.inc';
|
||||
$db = MySQLPDOTest::factory();
|
||||
|
||||
$db->exec('DROP PROCEDURE IF EXISTS p');
|
||||
$db->exec('CREATE PROCEDURE p() BEGIN SELECT 1 AS "one"; END');
|
||||
|
||||
$stmt = $db->query("CALL p()");
|
||||
do {
|
||||
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
|
||||
} while ($stmt->nextRowset());
|
||||
var_dump($stmt->errorInfo());
|
||||
|
||||
$stmt = $db->query('SELECT 2 AS "two"');
|
||||
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
|
||||
var_dump($stmt->errorInfo());
|
||||
print "done!";
|
||||
?>
|
||||
@@ -0,0 +1,31 @@
|
||||
array(1) {
|
||||
[0]=>
|
||||
array(1) {
|
||||
[%u|b%"one"]=>
|
||||
%unicode|string%(1) "1"
|
||||
}
|
||||
}
|
||||
array(3) {
|
||||
[0]=>
|
||||
%unicode|string%(5) "00000"
|
||||
[1]=>
|
||||
NULL
|
||||
[2]=>
|
||||
NULL
|
||||
}
|
||||
array(1) {
|
||||
[0]=>
|
||||
array(1) {
|
||||
[%u|b%"two"]=>
|
||||
%unicode|string%(1) "2"
|
||||
}
|
||||
}
|
||||
array(3) {
|
||||
[0]=>
|
||||
%unicode|string%(5) "00000"
|
||||
[1]=>
|
||||
NULL
|
||||
[2]=>
|
||||
NULL
|
||||
}
|
||||
done!
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
|
||||
$db = MySQLPDOTest::factory();
|
||||
|
||||
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')");
|
||||
|
||||
$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')");
|
||||
|
||||
}
|
||||
|
||||
print "Emulated Prepared Statements...\n";
|
||||
$db = MySQLPDOTest::factory();
|
||||
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1);
|
||||
$db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, 1);
|
||||
bug_42499($db);
|
||||
|
||||
print "Native Prepared Statements...\n";
|
||||
$db = MySQLPDOTest::factory();
|
||||
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0);
|
||||
$db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, 1);
|
||||
bug_42499($db);
|
||||
|
||||
$db = MySQLPDOTest::factory();
|
||||
$db->exec('DROP TABLE IF EXISTS test');
|
||||
|
||||
print "done!";
|
||||
?>
|
||||
@@ -0,0 +1,19 @@
|
||||
Emulated Prepared Statements...
|
||||
array(1) {
|
||||
[0]=>
|
||||
array(1) {
|
||||
[%u|b%"_id"]=>
|
||||
%unicode|string%(1) "a"
|
||||
}
|
||||
}
|
||||
HipHop Warning: %a
|
||||
Native Prepared Statements...
|
||||
array(1) {
|
||||
[0]=>
|
||||
array(1) {
|
||||
[%u|b%"_id"]=>
|
||||
%unicode|string%(1) "a"
|
||||
}
|
||||
}
|
||||
HipHop Warning: %a
|
||||
done!
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
|
||||
|
||||
$dsn = MySQLPDOTest::getDSN();
|
||||
$db = new PDO($dsn, PDO_MYSQL_TEST_USER, PDO_MYSQL_TEST_PASS, array(PDO::ATTR_PERSISTENT => true));
|
||||
|
||||
print "done!";
|
||||
?>
|
||||
@@ -0,0 +1 @@
|
||||
done!
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
require dirname(__FILE__) . '/config.inc';
|
||||
require dirname(__FILE__) . '/../ext-pdo/pdo_test.inc';
|
||||
$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
|
||||
|
||||
function bug_44454($db) {
|
||||
|
||||
try {
|
||||
|
||||
$db->exec('DROP TABLE IF EXISTS test');
|
||||
$db->exec('CREATE TABLE test(a INT, b INT, UNIQUE KEY idx_ab (a, b))');
|
||||
$db->exec('INSERT INTO test(a, b) VALUES (1, 1)');
|
||||
|
||||
$stmt = $db->query('SELECT a, b FROM test');
|
||||
printf("... SELECT has returned %d row...\n", $stmt->rowCount());
|
||||
while ($row = $stmt->fetch()) {
|
||||
try {
|
||||
printf("... INSERT should fail...\n");
|
||||
$db->exec('INSERT INTO test(a, b) VALUES (1, 1)');
|
||||
} catch (Exception $e) {
|
||||
printf("... STMT - %s\n", var_export($stmt->errorCode(), true));
|
||||
printf("... PDO - %s\n", var_export($db->errorInfo(), true));
|
||||
}
|
||||
}
|
||||
|
||||
$db->exec('DROP TABLE IF EXISTS test');
|
||||
$db->exec('CREATE TABLE test(a INT, b INT, UNIQUE KEY idx_ab (a, b))');
|
||||
$db->exec('INSERT INTO test(a, b) VALUES (1, 1)');
|
||||
|
||||
} catch (Exception $e) {
|
||||
printf("... While error %s\n", $e->getMessage()); ;
|
||||
}
|
||||
|
||||
$stmt = $db->query('SELECT a, b FROM test');
|
||||
printf("... SELECT has returned %d row...\n", $stmt->rowCount());
|
||||
foreach ($stmt as $row) {
|
||||
try {
|
||||
printf("... INSERT should fail...\n");
|
||||
$db->exec('INSERT INTO test(a, b) VALUES (1, 1)');
|
||||
} catch (Exception $e) {
|
||||
printf("... STMT - %s\n", var_export($stmt->errorCode(), true));
|
||||
printf("... PDO - %s\n", var_export($db->errorInfo(), true));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
|
||||
print "Native Prepared Statements\n";
|
||||
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0);
|
||||
bug_44454($db);
|
||||
|
||||
print "\nEmulated Prepared Statements\n";
|
||||
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1);
|
||||
bug_44454($db);
|
||||
|
||||
print "done!";
|
||||
?><?php
|
||||
require dirname(__FILE__) . '/mysql_pdo_test.inc';
|
||||
$db = MySQLPDOTest::factory();
|
||||
$db->exec('DROP TABLE IF EXISTS test');
|
||||
?>
|
||||
@@ -0,0 +1,36 @@
|
||||
Native Prepared Statements
|
||||
... SELECT has returned 1 row...
|
||||
... INSERT should fail...
|
||||
... STMT - '00000'
|
||||
... PDO - array (
|
||||
0 => '23000',
|
||||
1 => 1062,
|
||||
2 => 'Duplicate entry \'1-1\' for key %s',
|
||||
)
|
||||
... SELECT has returned 1 row...
|
||||
... INSERT should fail...
|
||||
... STMT - '00000'
|
||||
... PDO - array (
|
||||
0 => '23000',
|
||||
1 => 1062,
|
||||
2 => 'Duplicate entry \'1-1\' for key %s',
|
||||
)
|
||||
|
||||
Emulated Prepared Statements
|
||||
... SELECT has returned 1 row...
|
||||
... INSERT should fail...
|
||||
... STMT - '00000'
|
||||
... PDO - array (
|
||||
0 => '23000',
|
||||
1 => 1062,
|
||||
2 => 'Duplicate entry \'1-1\' for key %s',
|
||||
)
|
||||
... SELECT has returned 1 row...
|
||||
... INSERT should fail...
|
||||
... STMT - '00000'
|
||||
... PDO - array (
|
||||
0 => '23000',
|
||||
1 => 1062,
|
||||
2 => 'Duplicate entry \'1-1\' for key %s',
|
||||
)
|
||||
done!
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
require dirname(__FILE__) . '/config.inc';
|
||||
require dirname(__FILE__) . '/../ext-pdo/pdo_test.inc';
|
||||
$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
|
||||
|
||||
function bug_44707($db) {
|
||||
|
||||
$db->exec('DROP TABLE IF EXISTS test');
|
||||
$db->exec('CREATE TABLE test(id INT, mybool TINYINT)');
|
||||
|
||||
$id = 1;
|
||||
$mybool = false;
|
||||
var_dump($mybool);
|
||||
|
||||
$stmt = $db->prepare('INSERT INTO test(id, mybool) VALUES (?, ?)');
|
||||
$stmt->bindParam(1, $id);
|
||||
// From MySQL 4.1 on boolean and TINYINT don't match! INSERT will fail.
|
||||
// Versions prior to 4.1 have a weak test and will accept this.
|
||||
$stmt->bindParam(2, $mybool, PDO::PARAM_BOOL);
|
||||
var_dump($mybool);
|
||||
|
||||
$stmt->execute();
|
||||
var_dump($mybool);
|
||||
|
||||
$stmt = $db->query('SELECT * FROM test');
|
||||
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
|
||||
|
||||
$stmt = $db->prepare('INSERT INTO test(id, mybool) VALUES (?, ?)');
|
||||
$stmt->bindParam(1, $id);
|
||||
// INT and integer work well together
|
||||
$stmt->bindParam(2, $mybool, PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
|
||||
$stmt = $db->query('SELECT * FROM test');
|
||||
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
// This is beyond the control of the driver... - the driver never gets in touch with bound values
|
||||
print "Emulated Prepared Statements\n";
|
||||
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1);
|
||||
bug_44707($db);
|
||||
*/
|
||||
|
||||
print "Native Prepared Statements\n";
|
||||
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0);
|
||||
bug_44707($db);
|
||||
|
||||
print "done!";
|
||||
?>
|
||||
@@ -0,0 +1,16 @@
|
||||
Native Prepared Statements
|
||||
bool(false)
|
||||
bool(false)
|
||||
bool(false)
|
||||
array(0) {
|
||||
}
|
||||
array(1) {
|
||||
[0]=>
|
||||
array(2) {
|
||||
[%u|b%"id"]=>
|
||||
%unicode|string%(1) "1"
|
||||
[%u|b%"mybool"]=>
|
||||
%unicode|string%(1) "0"
|
||||
}
|
||||
}
|
||||
done!
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
require dirname(__FILE__) . '/config.inc';
|
||||
require dirname(__FILE__) . '/../ext-pdo/pdo_test.inc';
|
||||
$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
|
||||
|
||||
function bug_45120($db) {
|
||||
|
||||
$stmt = $db->prepare("SELECT 1 AS 'one'");
|
||||
if (true !== $stmt->execute())
|
||||
printf("[001] Execute has failed: %s\n", var_export($stmt->errorInfo(), true));
|
||||
|
||||
$res = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
if ($res['one'] != 1)
|
||||
printf("[002] Wrong results: %s\n", var_export($res, true));
|
||||
|
||||
if (true !== $stmt->execute())
|
||||
printf("[003] Execute has failed: %s\n", var_export($stmt->errorInfo(), true));
|
||||
|
||||
$res = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
if ($res['one'] != 1)
|
||||
printf("[004] Wrong results: %s\n", var_export($res, true));
|
||||
|
||||
}
|
||||
|
||||
print "Emulated Prepared Statements\n";
|
||||
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1);
|
||||
bug_45120($db);
|
||||
|
||||
print "Native Prepared Statements\n";
|
||||
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0);
|
||||
bug_45120($db);
|
||||
|
||||
print "done!";
|
||||
?>
|
||||
@@ -0,0 +1,3 @@
|
||||
Emulated Prepared Statements
|
||||
Native Prepared Statements
|
||||
done!
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
require dirname(__FILE__) . '/../ext-pdo/pdo_test.inc';
|
||||
$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
|
||||
|
||||
function changeDSN($original, $new_options) {
|
||||
$old_options = array();
|
||||
$dsn = substr($original,
|
||||
strpos($original, ':') + 1,
|
||||
strlen($original));
|
||||
|
||||
// no real parser - any excotic setting can fool us
|
||||
$parts = explode(';', $dsn);
|
||||
foreach ($parts as $k => $v) {
|
||||
$tmp = explode('=', $v);
|
||||
if (count($tmp) == 2)
|
||||
$old_options[$tmp[0]] = $tmp[1];
|
||||
}
|
||||
|
||||
$options = $old_options;
|
||||
foreach ($new_options as $k => $v)
|
||||
$options[$k] = $v;
|
||||
|
||||
$dsn = 'mysql:';
|
||||
foreach ($options as $k => $v)
|
||||
$dsn .= sprintf('%s=%s;', $k, $v);
|
||||
|
||||
$dsn = substr($dsn, 0, strlen($dsn) -1);
|
||||
|
||||
return $dsn;
|
||||
}
|
||||
|
||||
|
||||
if (1 === @$db->exec('CREATE DATABASE `crazy;dbname`')) {
|
||||
$dsn = changeDSN(getenv('PDOTEST_DSN'), array('dbname' => 'crazy;;dbname'));
|
||||
$user = getenv('PDOTEST_USER');
|
||||
$pass = getenv('PDOTEST_PASS');
|
||||
|
||||
new PDO($dsn, $user, $pass);
|
||||
}
|
||||
echo 'done!';
|
||||
?><?php
|
||||
require dirname(__FILE__) . '/../ext-pdo/pdo_test.inc';
|
||||
$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
|
||||
|
||||
@$db->exec('DROP DATABASE IF EXISTS `crazy;dbname`');
|
||||
?>
|
||||
@@ -0,0 +1 @@
|
||||
done!
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
require dirname(__FILE__) . '/../ext-pdo/pdo_test.inc';
|
||||
$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
|
||||
$query = $db->prepare('SELECT 1 AS num');
|
||||
$query->execute();
|
||||
if(!is_array($query->getColumnMeta(0))) die('FAIL!');
|
||||
$query->nextRowset();
|
||||
$query->execute();
|
||||
if(!is_array($query->getColumnMeta(0))) die('FAIL!');
|
||||
echo 'done!';
|
||||
?>
|
||||
@@ -0,0 +1 @@
|
||||
done!
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
|
||||
$db = MySQLPDOTest::factory();
|
||||
|
||||
$db->query('DROP TABLE IF EXISTS test');
|
||||
$db->query('create table `test`( `id` int )');
|
||||
|
||||
$handle1 = $db->prepare('insert into test(id) values(1);
|
||||
select * from test where id = ?;
|
||||
update test set id = 2 where id = ?;');
|
||||
|
||||
$handle1->bindValue('1', '1');
|
||||
$handle1->bindValue('2', '1');
|
||||
|
||||
$handle1->execute();
|
||||
$i = 1;
|
||||
print("Handle 1:\n");
|
||||
do {
|
||||
print('Rowset ' . $i++ . "\n");
|
||||
if ($handle1->columnCount() > 0)
|
||||
print("Results detected\n");
|
||||
} while($handle1->nextRowset());
|
||||
|
||||
$handle2 = $db->prepare('select * from test where id = ?;
|
||||
update test set id = 1 where id = ?;');
|
||||
|
||||
$handle2->bindValue('1', '2');
|
||||
$handle2->bindValue('2', '2');
|
||||
|
||||
$handle2->execute();
|
||||
|
||||
$i = 1;
|
||||
print("Handle 2:\n");
|
||||
do {
|
||||
print('Rowset ' . $i++ . "\n");
|
||||
if ($handle2->columnCount() > 0)
|
||||
print("Results detected\n");
|
||||
} while($handle2->nextRowset());
|
||||
|
||||
$handle3 = $db->prepare('update test set id = 2 where id = ?;
|
||||
select * from test where id = ?;');
|
||||
|
||||
$handle3->bindValue('1', '1');
|
||||
$handle3->bindValue('2', '2');
|
||||
|
||||
$handle3->execute();
|
||||
|
||||
$i = 1;
|
||||
print("Handle 3:\n");
|
||||
do {
|
||||
print('Rowset ' . $i++ . "\n");
|
||||
if ($handle3->columnCount() > 0)
|
||||
print("Results detected\n");
|
||||
} while($handle3->nextRowset());
|
||||
|
||||
$handle4 = $db->prepare('insert into test(id) values(3);
|
||||
update test set id = 2 where id = ?;
|
||||
select * from test where id = ?;');
|
||||
|
||||
$handle4->bindValue('1', '3');
|
||||
$handle4->bindValue('2', '2');
|
||||
|
||||
$handle4->execute();
|
||||
|
||||
$i = 1;
|
||||
print("Handle 4:\n");
|
||||
do {
|
||||
print('Rowset ' . $i++ . "\n");
|
||||
if ($handle1->columnCount() > 0)
|
||||
print("Results detected\n");
|
||||
} while($handle1->nextRowset());
|
||||
|
||||
$db->query("DROP TABLE test");
|
||||
?><?php
|
||||
require dirname(__FILE__) . '/mysql_pdo_test.inc';
|
||||
MySQLPDOTest::dropTestTable();
|
||||
?>
|
||||
@@ -0,0 +1,18 @@
|
||||
Handle 1:
|
||||
Rowset 1
|
||||
Rowset 2
|
||||
Results detected
|
||||
Rowset 3
|
||||
Handle 2:
|
||||
Rowset 1
|
||||
Results detected
|
||||
Rowset 2
|
||||
Handle 3:
|
||||
Rowset 1
|
||||
Rowset 2
|
||||
Results detected
|
||||
Handle 4:
|
||||
Rowset 1
|
||||
Rowset 2
|
||||
Rowset 3
|
||||
Results detected
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
|
||||
|
||||
$attr = getenv('PDOTEST_ATTR');
|
||||
if (!$attr) {
|
||||
$attr = array();
|
||||
} else {
|
||||
$attr = unserialize($attr);
|
||||
}
|
||||
$attr[PDO::ATTR_PERSISTENT] = true;
|
||||
$attr[PDO::ATTR_EMULATE_PREPARES] = false;
|
||||
putenv('PDOTEST_ATTR='.serialize($attr));
|
||||
|
||||
$db = MySQLPDOTest::factory();
|
||||
|
||||
$stmt = $db->prepare("SELECT 1");
|
||||
$stmt->execute();
|
||||
|
||||
foreach ($stmt as $line) {
|
||||
var_dump($line);
|
||||
}
|
||||
|
||||
print "done!";
|
||||
?>
|
||||
@@ -0,0 +1,7 @@
|
||||
array(2) {
|
||||
[1]=>
|
||||
int(1)
|
||||
[2]=>
|
||||
int(1)
|
||||
}
|
||||
done!
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
require dirname(__FILE__) . '/../ext-pdo/pdo_test.inc';
|
||||
$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
|
||||
|
||||
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
|
||||
echo "NULL-Byte before first placeholder:\n";
|
||||
$s = $db->prepare("SELECT \"a\0b\", ?");
|
||||
$s->bindValue(1,"c");
|
||||
$s->execute();
|
||||
$r = $s->fetch();
|
||||
echo "Length of item 0: ".strlen($r[0]).", Value of item 1: ".$r[1]."\n";
|
||||
|
||||
echo "\nOpen comment:\n";
|
||||
try {
|
||||
$s = $db->prepare("SELECT /*");
|
||||
$s->execute();
|
||||
} catch (Exception $e) {
|
||||
echo "Error code: ".$e->getCode()."\n";
|
||||
}
|
||||
|
||||
echo "\ndone!\n";
|
||||
?>
|
||||
@@ -0,0 +1,7 @@
|
||||
NULL-Byte before first placeholder:
|
||||
Length of item 0: 3, Value of item 1: c
|
||||
|
||||
Open comment:
|
||||
Error code: 42000
|
||||
|
||||
done!
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
|
||||
$db = MySQLPDOTest::factory();
|
||||
|
||||
function bug_pecl_1295($db) {
|
||||
|
||||
$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'");
|
||||
$stmt->execute();
|
||||
$stmt = $db->prepare("UPDATE test SET id = 'c'");
|
||||
$stmt->execute();
|
||||
$stmt = $db->prepare('SELECT id FROM test');
|
||||
$stmt->execute();
|
||||
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
|
||||
$stmt->closeCursor();
|
||||
|
||||
}
|
||||
|
||||
printf("Emulated...\n");
|
||||
$db = MySQLPDOTest::factory();
|
||||
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1);
|
||||
bug_pecl_1295($db);
|
||||
|
||||
printf("Native...\n");
|
||||
$db = MySQLPDOTest::factory();
|
||||
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0);
|
||||
bug_pecl_1295($db);
|
||||
|
||||
$db->exec('DROP TABLE IF EXISTS test');
|
||||
print "done!";
|
||||
?>
|
||||
@@ -0,0 +1,17 @@
|
||||
Emulated...
|
||||
array(1) {
|
||||
[0]=>
|
||||
array(1) {
|
||||
[%u|b%"id"]=>
|
||||
%unicode|string%(1) "c"
|
||||
}
|
||||
}
|
||||
Native...
|
||||
array(1) {
|
||||
[0]=>
|
||||
array(1) {
|
||||
[%u|b%"id"]=>
|
||||
%unicode|string%(1) "c"
|
||||
}
|
||||
}
|
||||
done!
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
|
||||
$db = MySQLPDOTest::factory();
|
||||
|
||||
function bug_pecl_7976($db) {
|
||||
|
||||
$db->exec('DROP PROCEDURE IF EXISTS p');
|
||||
$db->exec('CREATE PROCEDURE p() BEGIN SELECT "1" AS _one; END;');
|
||||
|
||||
$stmt = $db->query('CALL p()');
|
||||
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
|
||||
$stmt->closeCursor();
|
||||
|
||||
$stmt = $db->query('CALL p()');
|
||||
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
|
||||
$stmt->closeCursor();
|
||||
|
||||
}
|
||||
|
||||
printf("Emulated...\n");
|
||||
$db = MySQLPDOTest::factory();
|
||||
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1);
|
||||
bug_pecl_7976($db);
|
||||
|
||||
printf("Native...\n");
|
||||
$db = MySQLPDOTest::factory();
|
||||
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0);
|
||||
bug_pecl_7976($db);
|
||||
|
||||
print "done!";
|
||||
?><?php
|
||||
require dirname(__FILE__) . '/mysql_pdo_test.inc';
|
||||
$db = MySQLPDOTest::factory();
|
||||
$db->exec('DROP PROCEDURE IF EXISTS p');
|
||||
?>
|
||||
@@ -0,0 +1,31 @@
|
||||
Emulated...
|
||||
array(1) {
|
||||
[0]=>
|
||||
array(1) {
|
||||
[%u|b%"_one"]=>
|
||||
%unicode|string%(1) "1"
|
||||
}
|
||||
}
|
||||
array(1) {
|
||||
[0]=>
|
||||
array(1) {
|
||||
[%u|b%"_one"]=>
|
||||
%unicode|string%(1) "1"
|
||||
}
|
||||
}
|
||||
Native...
|
||||
array(1) {
|
||||
[0]=>
|
||||
array(1) {
|
||||
[%u|b%"_one"]=>
|
||||
%unicode|string%(1) "1"
|
||||
}
|
||||
}
|
||||
array(1) {
|
||||
[0]=>
|
||||
array(1) {
|
||||
[%u|b%"_one"]=>
|
||||
%unicode|string%(1) "1"
|
||||
}
|
||||
}
|
||||
done!
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
require dirname(__FILE__) . '/../ext-pdo/pdo_test.inc';
|
||||
$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
|
||||
|
||||
print_r($db->query("CREATE TABLE test (id int auto_increment primary key, num int)"));
|
||||
|
||||
print_r($db->query("INSERT INTO test (id, num) VALUES (23, 42)"));
|
||||
|
||||
print_r($db->query("INSERT INTO test (num) VALUES (451)"));
|
||||
|
||||
print_r($db->lastInsertId());
|
||||
@@ -0,0 +1,13 @@
|
||||
PDOStatement Object
|
||||
(
|
||||
[queryString] => CREATE TABLE test (id int auto_increment primary key, num int)
|
||||
)
|
||||
PDOStatement Object
|
||||
(
|
||||
[queryString] => INSERT INTO test (id, num) VALUES (23, 42)
|
||||
)
|
||||
PDOStatement Object
|
||||
(
|
||||
[queryString] => INSERT INTO test (num) VALUES (451)
|
||||
)
|
||||
24
|
||||
@@ -0,0 +1,280 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
|
||||
|
||||
function tryandcatch($offset, $code) {
|
||||
|
||||
try {
|
||||
eval($code);
|
||||
assert(sprintf("[%03d] Should have failed\n", $offset) != '');
|
||||
} catch (PDOException $e) {
|
||||
return sprintf("[%03d] %s, [%s] %s\n",
|
||||
$offset,
|
||||
$e->getMessage(),
|
||||
(isset($db) && is_object($db)) ? $db->errorCode() : 'n/a',
|
||||
(isset($db) && is_object($db)) ? implode(' ', $db->errorInfo()) : 'n/a');
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
if (NULL !== ($db = @new PDO()))
|
||||
printf("[001] Too few parameters\n");
|
||||
|
||||
print tryandcatch(2, '$db = new PDO(chr(0));');
|
||||
print tryandcatch(3, '$db = new PDO("a" . chr(0) . "b");');
|
||||
print tryandcatch(4, '$db = new PDO("MYSQL");');
|
||||
print tryandcatch(5, '$db = new PDO("mysql");');
|
||||
print tryandcatch(6, '$db = new PDO("mysql ");');
|
||||
print tryandcatch(7, '$db = new PDO("fantasyandfriends :");');
|
||||
|
||||
$dsn = PDO_MYSQL_TEST_DSN;
|
||||
// MySQL Server might accept anonymous connections, don't
|
||||
// print anything
|
||||
tryandcatch(8, '$db = new PDO("' . $dsn . '");');
|
||||
|
||||
$user = 'dontcreatesuchauser';
|
||||
$pass = 'withthispassword';
|
||||
print tryandcatch(9, '$db = new PDO("' . $dsn . '", "' . $user . '", "' . $pass . '");');
|
||||
|
||||
// should fail
|
||||
$dsn = 'mysql:';
|
||||
print tryandcatch(10, '$db = new PDO("' . $dsn . '", "' . $user . '", "' . $pass . '");');
|
||||
|
||||
$dsn = PDO_MYSQL_TEST_DSN;
|
||||
$user = PDO_MYSQL_TEST_USER;
|
||||
$pass = PDO_MYSQL_TEST_PASS;
|
||||
// should work...
|
||||
$db = new PDO($dsn, $user, $pass);
|
||||
|
||||
$dsn = 'mysql:invalid=foo';
|
||||
print tryandcatch(11, '$db = new PDO("' . $dsn . '", "' . $user . '", "' . $pass . '");');
|
||||
|
||||
$dsn = 'mysql:' . str_repeat('howmuch=canpdoeat;', 1000);
|
||||
print tryandcatch(12, '$db = new PDO("' . $dsn . '", "' . $user . '", "' . $pass . '");');
|
||||
|
||||
$dsn = 'mysql:' . str_repeat('abcdefghij', 1024 * 10) . '=somevalue';
|
||||
print tryandcatch(13, '$db = new PDO("' . $dsn . '", "' . $user . '", "' . $pass . '");');
|
||||
|
||||
if (PDO_MYSQL_TEST_HOST) {
|
||||
$host = PDO_MYSQL_TEST_HOST;
|
||||
$invalid_host = $host . 'invalid';
|
||||
|
||||
// last host specification should be the one used
|
||||
$dsn = MySQLPDOTest::getDSN(array('host' => $host), 'host=' . $invalid_host);
|
||||
try { $db = @new PDO($dsn, $user, $pass); assert(false); printf("%s\n", $dsn); } catch (PDOException $e) {
|
||||
$tmp = $e->getMessage();
|
||||
if (!stristr($tmp, 'HY000') && !stristr($tmp, '2005') && !stristr($tmp, '2002'))
|
||||
printf("[014] Cannot find proper error codes: %s\n", $tmp);
|
||||
}
|
||||
|
||||
$dsn = MySQLPDOTest::getDSN(array('host' => $invalid_host), 'host=' . $host);
|
||||
try { $db = @new PDO($dsn, $user, $pass); } catch (PDOException $e) {
|
||||
printf("[015] DSN=%s, %s\n", $dsn, $e->getMessage());
|
||||
}
|
||||
|
||||
$invalid_host = '-' . chr(0);
|
||||
|
||||
$dsn = MySQLPDOTest::getDSN(array('host' => $invalid_host));
|
||||
try { $db = @new PDO($dsn, $user, $pass); assert(false); printf("%s\n", $dsn); } catch (PDOException $e) {
|
||||
$tmp = $e->getMessage();
|
||||
if (!stristr($tmp, 'HY000') && !stristr($tmp, '2005') && !stristr($tmp, '2002'))
|
||||
printf("[016] Cannot find proper error codes: %s\n", $tmp);
|
||||
}
|
||||
|
||||
// parsing should not get confused by chr(0)
|
||||
$dsn = MySQLPDOTest::getDSN(array('host' => $invalid_host), 'host=' . $host);
|
||||
try { $db = @new PDO($dsn, $user, $pass); } catch (PDOException $e) {
|
||||
printf("[017] DSN=%s, %s\n", $dsn, $e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// what about long values for a valid option ...
|
||||
// hostnames > 1024 chars break on some NIS-enabled FreeBSD...
|
||||
$dsn = MySQLPDOTest::getDSN(array('host' => str_repeat('0123456789', 100)));
|
||||
try { $db = @new PDO($dsn, $user, $pass); assert(false); printf("%s\n", $dsn); } catch (PDOException $e) {
|
||||
$tmp = $e->getMessage();
|
||||
if (!stristr($tmp, 'HY000') && !stristr($tmp, '2005') && !stristr($tmp, '2002'))
|
||||
printf("[018] Cannot find proper error codes: %s\n", $tmp);
|
||||
}
|
||||
|
||||
if (PDO_MYSQL_TEST_PORT && (PDO_MYSQL_TEST_SOCKET == '')) {
|
||||
// Playing with the port makes only sense if no socket gets used
|
||||
|
||||
$port = PDO_MYSQL_TEST_PORT;
|
||||
// let's hope we don't hit a MySQL running on that port...
|
||||
$invalid_port = $port * 2;
|
||||
|
||||
$dsn = MySQLPDOTest::getDSN(array('port' => $port), 'port=' . $invalid_port);
|
||||
try { $db = @new PDO($dsn, $user, $pass); assert(false); printf("%s\n", $dsn); } catch (PDOException $e) {
|
||||
$tmp = $e->getMessage();
|
||||
if (!stristr($tmp, 'HY000') && !stristr($tmp, '2005'))
|
||||
printf("[019] Cannot find proper error codes: %s\n", $tmp);
|
||||
}
|
||||
|
||||
$dsn = MySQLPDOTest::getDSN(array('port' => $invalid_port), 'port=' . $port);
|
||||
try { $db = @new PDO($dsn, $user, $pass); } catch (PDOException $e) {
|
||||
printf("[020] DSN=%s, %s\n", $dsn, $e->getMessage());
|
||||
}
|
||||
|
||||
$invalid_port = 'abc';
|
||||
$dsn = MySQLPDOTest::getDSN(array('port' => $port), 'port=' . $invalid_port);
|
||||
try {
|
||||
$db = @new PDO($dsn, $user, $pass);
|
||||
// atoi('abc') = 0, 0 -> fallback to default 3306 -> may or may not fail!
|
||||
} catch (PDOException $e) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (PDO_MYSQL_TEST_DB) {
|
||||
$db = PDO_MYSQL_TEST_DB;
|
||||
$invalid_db = 'letshopeitdoesnotexist';
|
||||
|
||||
$dsn = MySQLPDOTest::getDSN(array('dbname' => $db), 'dbname=' . $invalid_db);
|
||||
try { $db = @new PDO($dsn, $user, $pass); assert(false); printf("%s\n", $dsn); } catch (PDOException $e) {
|
||||
$tmp = $e->getMessage();
|
||||
if (!stristr($tmp, '42000') && !stristr($tmp, '1049'))
|
||||
printf("[022] Cannot find proper error codes: %s\n", $tmp);
|
||||
}
|
||||
|
||||
$dsn = MySQLPDOTest::getDSN(array('dbname' => $invalid_db), 'dbname=' . $db);
|
||||
try { $db = @new PDO($dsn, $user, $pass); } catch (PDOException $e) {
|
||||
printf("[023] DSN=%s, %s\n", $dsn, $e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (PDO_MYSQL_TEST_SOCKET && (stristr(PDO_MYSQL_TEST_DSN, PDO_MYSQL_TEST_SOCKET) !== false)) {
|
||||
$socket = PDO_MYSQL_TEST_SOCKET;
|
||||
$invalid_socket = '/lets/hope/it/does/not/exist';
|
||||
|
||||
$dsn = MySQLPDOTest::getDSN(array('unix_socket' => $socket), 'unix_socket=' . $invalid_socket);
|
||||
try { $db = @new PDO($dsn, $user, $pass); assert(false); printf("%s\n", $dsn); } catch (PDOException $e) {
|
||||
$tmp = $e->getMessage();
|
||||
if (!stristr($tmp, 'HY000') && !stristr($tmp, '2002'))
|
||||
printf("[024] Cannot find proper error codes: %s\n", $tmp);
|
||||
}
|
||||
|
||||
$dsn = MySQLPDOTest::getDSN(array('unix_socket' => $invalid_socket), 'unix_socket=' . $socket);
|
||||
try { $db = @new PDO($dsn, $user, $pass); } catch (PDOException $e) {
|
||||
printf("[025] DSN=%s, %s\n", $dsn, $e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$have_charset_support = false;
|
||||
$dsn = MySQLPDOTest::getDSN();
|
||||
try {
|
||||
$db = new PDO($dsn, $user, $pass);
|
||||
$stmt = $db->query('SELECT VERSION() as _version');
|
||||
$version = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
$tmp = explode('.', $version['_version']);
|
||||
if ((count($tmp) == 3) &&
|
||||
(($tmp[0] >= 4 && $tmp[1] >= 1) || ($tmp[0] >= 5))) {
|
||||
// MySQL Server 4.1 - charset support available
|
||||
$have_charset_support = true;
|
||||
}
|
||||
|
||||
} catch (PDOException $e) {
|
||||
printf("[026] DSN=%s, %s\n", $dsn, $e->getMessage());
|
||||
}
|
||||
|
||||
if (PDO_MYSQL_TEST_CHARSET) {
|
||||
$charset = PDO_MYSQL_TEST_CHARSET;
|
||||
$invalid_charset = 'invalid';
|
||||
|
||||
if ($have_charset_support) {
|
||||
$dsn = MySQLPDOTest::getDSN();
|
||||
$db = new PDO($dsn, $user, $pass);
|
||||
$stmt = $db->query(sprintf('SHOW CHARACTER SET LIKE "%s"', $charset));
|
||||
$tmp = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$have_charset = (empty($tmp)) ? false : true;
|
||||
|
||||
if ($have_charset) {
|
||||
$dsn = MySQLPDOTest::getDSN(array('charset' => $charset), 'charset=' . $invalid_charset);
|
||||
try {
|
||||
$db = @new PDO($dsn, $user, $pass);
|
||||
/* NOTE: MySQL does a fallback to the charset suggested during the handshake - no error - no bug! */
|
||||
} catch (PDOException $e) {
|
||||
$tmp = $e->getMessage();
|
||||
/* TODO: add proper codes */
|
||||
if (!stristr($tmp, 'sqlstatecode') || !stristr($tmp, 'mysqlinternalerrcode'))
|
||||
printf("[027] TODO - Cannot find proper error codes: %s\n", $tmp);
|
||||
}
|
||||
|
||||
$dsn = MySQLPDOTest::getDSN(array('charset' => $invalid_charset), 'charset=' . $charset);
|
||||
try {
|
||||
$db = @new PDO($dsn, $user, $pass);
|
||||
/* Strictly speaking we should test more: character_set_client, character_set_results, and character_set_connection */
|
||||
$stmt = $db->query('SELECT @@character_set_connection AS _charset');
|
||||
$tmp = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
if ($tmp['_charset'] != $charset)
|
||||
printf("[028] Character sets has not been set, @@character_set_connection reports '%s', expecting '%s'",
|
||||
$tmp['_charset'], $charset);
|
||||
} catch (PDOException $e) {
|
||||
printf("[029] DSN=%s, %s\n", $dsn, $e->getMessage());
|
||||
}
|
||||
} else {
|
||||
printf("[030] You're trying to run the tests with charset '%s' which seems not supported by the server!", $charset);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ($have_charset_support) {
|
||||
// In case the PDO_MYSQL_TEST_CHARSET interferes with any defaults
|
||||
// we do another test to verify that the charset has been set.
|
||||
$dsn = MySQLPDOTest::getDSN();
|
||||
$db = new PDO($dsn, $user, $pass);
|
||||
$stmt = $db->query('SHOW CHARACTER SET LIKE "latin1"');
|
||||
$tmp = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$have_latin1 =(empty($tmp)) ? false : true;
|
||||
$stmt = $db->query('SHOW CHARACTER SET LIKE "latin2"');
|
||||
$tmp = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$have_latin2 =(empty($tmp)) ? false : true;
|
||||
|
||||
if ($have_latin1 && $have_latin2) {
|
||||
// very likely we do have both of them...
|
||||
try {
|
||||
$dsn = MySQLPDOTest::getDSN(array('charset' => 'latin1'));
|
||||
$db = new PDO($dsn, $user, $pass);
|
||||
$stmt = $db->query('SELECT @@character_set_connection AS _charset');
|
||||
$tmp = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
if ($tmp['_charset'] != 'latin1')
|
||||
printf("[031] DSN = %s, Character sets has not been set, @@character_set_connection reports '%s', expecting '%s'",
|
||||
$dsn, $tmp['_charset'], 'latin1');
|
||||
|
||||
} catch (PDOException $e) {
|
||||
printf("[032] %s\n", $e->getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
$dsn = MySQLPDOTest::getDSN(array('charset' => 'latin2'));
|
||||
$db = new PDO($dsn, $user, $pass);
|
||||
$stmt = $db->query('SELECT @@character_set_connection AS _charset');
|
||||
$tmp = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
if ($tmp['_charset'] != 'latin2')
|
||||
printf("[033] DSN = %s, character sets has not been set, @@character_set_connection reports '%s', expecting '%s'",
|
||||
$dsn, $tmp['_charset'], 'latin2');
|
||||
|
||||
} catch (PDOException $e) {
|
||||
printf("[034] %s\n", $e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
} catch (PDOException $e) {
|
||||
printf("[001] %s, [%s] %s\n",
|
||||
$e->getMessage(),
|
||||
(is_object($db)) ? $db->errorCode() : 'n/a',
|
||||
(is_object($db)) ? implode(' ', $db->errorInfo()) : 'n/a');
|
||||
}
|
||||
|
||||
print "done!";
|
||||
?>
|
||||
@@ -0,0 +1,10 @@
|
||||
[002] invalid data source name, [n/a] n/a
|
||||
[003] invalid data source name, [n/a] n/a
|
||||
[004] invalid data source name, [n/a] n/a
|
||||
[005] invalid data source name, [n/a] n/a
|
||||
[006] invalid data source name, [n/a] n/a
|
||||
[007] could not find driver, [n/a] n/a
|
||||
[009] SQLSTATE[%s] [1045] Access denied for user 'dont%s'@'%s' (using password: YES), [n/a] n/a
|
||||
[010] SQLSTATE[%s] [1045] Access denied for user 'dont%s'@'%s' (using password: YES), [n/a] n/a
|
||||
[017] DSN=%s, SQLSTATE[%s] [%d] %s
|
||||
done!
|
||||
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
|
||||
|
||||
function set_option_and_check($offset, $option, $value, $option_desc) {
|
||||
|
||||
$dsn = MySQLPDOTest::getDSN();
|
||||
$user = PDO_MYSQL_TEST_USER;
|
||||
$pass = PDO_MYSQL_TEST_PASS;
|
||||
|
||||
try {
|
||||
$db = new PDO($dsn, $user, $pass, array($option => $value));
|
||||
if (!is_object($db) || ($value !== ($tmp = @$db->getAttribute($option))))
|
||||
printf("[%03d] Execting '%s'/%s got '%s'/%s' for options '%s'\n",
|
||||
$offset,
|
||||
$value, gettype($value),
|
||||
$tmp, gettype($tmp),
|
||||
$option_desc);
|
||||
} catch (PDOException $e) {
|
||||
printf("[%03d] %s\n", $offset, $e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
$dsn = MySQLPDOTest::getDSN();
|
||||
$user = PDO_MYSQL_TEST_USER;
|
||||
$pass = PDO_MYSQL_TEST_PASS;
|
||||
|
||||
$valid_options = array(
|
||||
/* pdo_dbh.c */
|
||||
PDO::ATTR_PERSISTENT => 'PDO::ATTR_PERSISTENT',
|
||||
PDO::ATTR_AUTOCOMMIT => 'PDO::ATTR_AUTOCOMMIT',
|
||||
/* mysql_driver.c */
|
||||
/* TODO Possible bug PDO::ATTR_TIMEOUT != MYSQLI_OPT_CONNECT_TIMEOUT*/
|
||||
PDO::ATTR_TIMEOUT => 'PDO::ATTR_TIMEOUT',
|
||||
PDO::ATTR_EMULATE_PREPARES => 'PDO::ATTR_EMULATE_PREPARES',
|
||||
|
||||
PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => 'PDO::MYSQL_ATTR_USE_BUFFERED_QUERY',
|
||||
PDO::MYSQL_ATTR_LOCAL_INFILE => 'PDO::MYSQL_ATTR_LOCAL_INFILE',
|
||||
PDO::MYSQL_ATTR_DIRECT_QUERY => 'PDO::MYSQL_ATTR_DIRECT_QUERY',
|
||||
|
||||
PDO::MYSQL_ATTR_INIT_COMMAND => 'PDO::MYSQL_ATTR_INIT_COMMAND',
|
||||
);
|
||||
|
||||
$defaults = array(
|
||||
PDO::ATTR_PERSISTENT => false,
|
||||
PDO::ATTR_AUTOCOMMIT => 1,
|
||||
/* TODO - why is this a valid option if getAttribute() does not support it?! */
|
||||
PDO::ATTR_TIMEOUT => false,
|
||||
PDO::ATTR_EMULATE_PREPARES => 1,
|
||||
PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => 1,
|
||||
/* TODO getAttribute() does not handle it */
|
||||
PDO::MYSQL_ATTR_LOCAL_INFILE => false,
|
||||
/* TODO getAttribute() does not handle it */
|
||||
PDO::MYSQL_ATTR_DIRECT_QUERY => 1,
|
||||
PDO::MYSQL_ATTR_INIT_COMMAND => '',
|
||||
);
|
||||
|
||||
if (NULL !== ($db = @new PDO($dsn, $user, $pass, 'wrong type')))
|
||||
printf("[001] Expecting NULL got %s/%s\n", gettype($db), $db);
|
||||
|
||||
if (!is_object($db = new PDO($dsn, $user, $pass, array())))
|
||||
printf("[002] Expecting object got %s/%s¸\n", gettype($db), $db);
|
||||
|
||||
do {
|
||||
$invalid = mt_rand(-1000, 1000);
|
||||
} while (isset($valid_options[$invalid]));
|
||||
if (is_object($db = new PDO($dsn, $user, $pass, array($invalid => true))))
|
||||
printf("[003] [TODO][CHANGEREQUEST] Please, lets not ignore invalid options and bail out!\n");
|
||||
|
||||
$db = new PDO($dsn, $user, $pass);
|
||||
foreach ($valid_options as $option => $name) {
|
||||
/* TODO getAttribute() is pretty poor in supporting the options, suppress errors */
|
||||
$tmp = @$db->getAttribute($option);
|
||||
if ($tmp !== $defaults[$option])
|
||||
printf("[003a] Expecting default value for '%s' of '%s'/%s, getAttribute() reports setting '%s'/%s\n",
|
||||
$name, $defaults[$option], gettype($defaults[$option]),
|
||||
$tmp, gettype($tmp));
|
||||
}
|
||||
|
||||
$db = new PDO($dsn, $user, $pass, array(PDO::ATTR_AUTOCOMMIT => true));
|
||||
if (!is_object($db) || !$db->getAttribute(PDO::ATTR_AUTOCOMMIT))
|
||||
printf("[004] Autocommit should be on\n");
|
||||
|
||||
$db = new PDO($dsn, $user, $pass, array(PDO::ATTR_AUTOCOMMIT => false));
|
||||
if (!is_object($db) || $db->getAttribute(PDO::ATTR_AUTOCOMMIT))
|
||||
printf("[005] Autocommit should be off\n");
|
||||
|
||||
/* TODO: no way to check ATTR_TIMEOUT settings */
|
||||
if (!is_object($db = new PDO($dsn, $user, $pass, array(PDO::ATTR_TIMEOUT => 10))))
|
||||
printf("[006] ATTR_TIMEOUT should be accepted\n");
|
||||
|
||||
if (!is_object($db = new PDO($dsn, $user, $pass, array(PDO::ATTR_TIMEOUT => PHP_INT_MAX))))
|
||||
printf("[007] ATTR_TIMEOUT should be accepted\n");
|
||||
|
||||
if (!is_object($db = new PDO($dsn, $user, $pass, array(PDO::ATTR_TIMEOUT => -PHP_INT_MAX))))
|
||||
printf("[008] ATTR_TIMEOUT should be accepted\n");
|
||||
|
||||
/* TODO: Its ugly that PDO::ATTR_EMULATE_PREPARES == PDO::MYSQL_ATTR_DIRECT_QUERY */
|
||||
$db = new PDO($dsn, $user, $pass, array(PDO::ATTR_EMULATE_PREPARES => true));
|
||||
if (!is_object($db))
|
||||
printf("[009] ATTR_EMULATE_PREPARES should be accepted and on\n");
|
||||
if (!$db->getAttribute(PDO::ATTR_EMULATE_PREPARES))
|
||||
printf("[010] [TODO][CHANGEREQUEST] ATTR_EMULATE_PREPARES should be on\n");
|
||||
if (!$db->getAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY))
|
||||
printf("[011] As PDO::MYSQL_ATTR_DIRECT_QUERY == PDO::ATTR_EMULATE_PREPARES
|
||||
and PDO::ATTR_EMULATE_PREPARES overrules the other, PDO::MYSQL_ATTR_DIRECT_QUERY should be on\n");
|
||||
|
||||
$db = new PDO($dsn, $user, $pass, array(PDO::ATTR_EMULATE_PREPARES => false));
|
||||
if (!is_object($db))
|
||||
printf("[012] ATTR_EMULATE_PREPARES should be accepted and on\n");
|
||||
if ($db->getAttribute(PDO::ATTR_EMULATE_PREPARES))
|
||||
printf("[013] [TODO][CHANGEREQUEST] ATTR_EMULATE_PREPARES should be off\n");
|
||||
if ($db->getAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY))
|
||||
printf("[014] As PDO::MYSQL_ATTR_DIRECT_QUERY == PDO::ATTR_EMULATE_PREPARES
|
||||
and PDO::ATTR_EMULATE_PREPARES overrules the other, PDO::MYSQL_ATTR_DIRECT_QUERY should be off\n");
|
||||
|
||||
// PDO::ATTR_EMULATE_PREPARES overrules PDO::MYSQL_ATTR_DIRECT_QUERY
|
||||
// TODO: is it clever that a generic setting overrules a specific setting?
|
||||
$db = new PDO($dsn, $user, $pass, array(PDO::ATTR_EMULATE_PREPARES => true, PDO::MYSQL_ATTR_DIRECT_QUERY => false));
|
||||
if (!$db->getAttribute(PDO::ATTR_EMULATE_PREPARES))
|
||||
printf("[015] PDO::ATTR_EMULATE_PREPARES should be on\n");
|
||||
if (!$db->getAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY))
|
||||
printf("[016] PDO::MYSQL_ATTR_DIRECT_QUERY should be on\n");
|
||||
|
||||
$db = new PDO($dsn, $user, $pass, array(PDO::ATTR_EMULATE_PREPARES => false, PDO::MYSQL_ATTR_DIRECT_QUERY => true));
|
||||
if ($db->getAttribute(PDO::ATTR_EMULATE_PREPARES))
|
||||
printf("[017] PDO::ATTR_EMULATE_PREPARES should be off\n");
|
||||
if ($db->getAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY))
|
||||
printf("[018] PDO::MYSQL_ATTR_DIRECT_QUERY should be off\n");
|
||||
|
||||
set_option_and_check(19, PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, 1, 'PDO::MYSQL_ATTR_USE_BUFFERED_QUERY');
|
||||
set_option_and_check(20, PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, 0, 'PDO::MYSQL_ATTR_USE_BUFFERED_QUERY');
|
||||
|
||||
set_option_and_check(21, PDO::MYSQL_ATTR_LOCAL_INFILE, true, 'PDO::MYSQL_ATTR_LOCAL_INFILE');
|
||||
set_option_and_check(22, PDO::MYSQL_ATTR_LOCAL_INFILE, false, 'PDO::MYSQL_ATTR_LOCAL_INFILE');
|
||||
|
||||
set_option_and_check(23, PDO::MYSQL_ATTR_INIT_COMMAND, 'SET @a=1', 'PDO::MYSQL_ATTR_INIT_COMMAND');
|
||||
set_option_and_check(24, PDO::MYSQL_ATTR_INIT_COMMAND, '', 'PDO::MYSQL_ATTR_INIT_COMMAND');
|
||||
set_option_and_check(25, PDO::MYSQL_ATTR_INIT_COMMAND, 'INSERT INTO nonexistent(invalid) VALUES (1)', 'PDO::MYSQL_ATTR_INIT_COMMAND');
|
||||
|
||||
set_option_and_check(33, PDO::MYSQL_ATTR_DIRECT_QUERY, 1, 'PDO::MYSQL_ATTR_DIRECT_QUERY');
|
||||
set_option_and_check(34, PDO::MYSQL_ATTR_DIRECT_QUERY, 0, 'PDO::MYSQL_ATTR_DIRECT_QUERY');
|
||||
|
||||
} catch (PDOException $e) {
|
||||
printf("[001] %s, [%s] %s\n",
|
||||
$e->getMessage(),
|
||||
(is_object($db)) ? $db->errorCode() : 'n/a',
|
||||
(is_object($db)) ? implode(' ', $db->errorInfo()) : 'n/a');
|
||||
}
|
||||
|
||||
print "done!";
|
||||
?>
|
||||
@@ -0,0 +1,16 @@
|
||||
[003] [TODO][CHANGEREQUEST] Please, lets not ignore invalid options and bail out!
|
||||
[003a] Expecting default value for 'PDO::ATTR_EMULATE_PREPARES' of '1'/integer, getAttribute() reports setting ''/boolean
|
||||
[003a] Expecting default value for 'PDO::MYSQL_ATTR_INIT_COMMAND' of ''/string, getAttribute() reports setting ''/boolean
|
||||
HipHop Warning: %a
|
||||
[010] [TODO][CHANGEREQUEST] ATTR_EMULATE_PREPARES should be on
|
||||
HipHop Warning: %a
|
||||
HipHop Warning: %a
|
||||
[015] PDO::ATTR_EMULATE_PREPARES should be on
|
||||
[016] PDO::MYSQL_ATTR_DIRECT_QUERY should be on
|
||||
HipHop Warning: %a
|
||||
[018] PDO::MYSQL_ATTR_DIRECT_QUERY should be off
|
||||
[021] Execting '1'/boolean got ''/boolean' for options 'PDO::MYSQL_ATTR_LOCAL_INFILE'
|
||||
[023] Execting 'SET @a=1'/string got ''/boolean' for options 'PDO::MYSQL_ATTR_INIT_COMMAND'
|
||||
[024] SQLSTATE[42000] [1065] Query was empty
|
||||
[025] SQLSTATE[42S02] [1146] Table '%s.nonexistent' doesn't exist
|
||||
done!
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
|
||||
|
||||
function set_option_and_check($offset, $option, $value, $option_desc, $ignore_diff = false) {
|
||||
|
||||
$dsn = MySQLPDOTest::getDSN();
|
||||
$user = PDO_MYSQL_TEST_USER;
|
||||
$pass = PDO_MYSQL_TEST_PASS;
|
||||
|
||||
try {
|
||||
$db = new PDO($dsn, $user, $pass, array($option => $value));
|
||||
if (!is_object($db) || (!$ignore_diff && ($value !== ($tmp = @$db->getAttribute($option)))))
|
||||
printf("[%03d] Execting '%s'/%s got '%s'/%s' for options '%s'\n",
|
||||
$offset,
|
||||
$value, gettype($value),
|
||||
$tmp, gettype($tmp),
|
||||
$option_desc);
|
||||
} catch (PDOException $e) {
|
||||
printf("[%03d] %s\n", $offset, $e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
$dsn = MySQLPDOTest::getDSN();
|
||||
$user = PDO_MYSQL_TEST_USER;
|
||||
$pass = PDO_MYSQL_TEST_PASS;
|
||||
|
||||
$valid_options = array();
|
||||
$valid_options[PDO::MYSQL_ATTR_MAX_BUFFER_SIZE] = 'PDO::MYSQL_ATTR_MAX_BUFFER_SIZE';
|
||||
$valid_options[PDO::MYSQL_ATTR_INIT_COMMAND] = 'PDO::MYSQL_ATTR_INIT_COMMAND';
|
||||
$valid_options[PDO::MYSQL_ATTR_READ_DEFAULT_FILE] = 'PDO::MYSQL_ATTR_READ_DEFAULT_FILE';
|
||||
$valid_options[PDO::MYSQL_ATTR_READ_DEFAULT_GROUP] = 'PDO::MYSQL_ATTR_READ_DEFAULT_GROUP';
|
||||
|
||||
$defaults[PDO::MYSQL_ATTR_MAX_BUFFER_SIZE] = 1048576;
|
||||
/* TODO getAttribute() does not handle it */
|
||||
$defaults[PDO::MYSQL_ATTR_INIT_COMMAND] = '';
|
||||
$defaults[PDO::MYSQL_ATTR_READ_DEFAULT_FILE] = false;
|
||||
$defaults[PDO::MYSQL_ATTR_READ_DEFAULT_GROUP] = false;
|
||||
|
||||
$db = new PDO($dsn, $user, $pass);
|
||||
foreach ($valid_options as $option => $name) {
|
||||
/* TODO getAttribute() is pretty poor in supporting the options, suppress errors */
|
||||
$tmp = @$db->getAttribute($option);
|
||||
if ($tmp !== $defaults[$option])
|
||||
printf("[001] Expecting default value for '%s' of '%s'/%s, getAttribute() reports setting '%s'/%s\n",
|
||||
$name, $defaults[$option], gettype($defaults[$option]),
|
||||
$tmp, gettype($tmp));
|
||||
}
|
||||
|
||||
set_option_and_check(26, PDO::MYSQL_ATTR_READ_DEFAULT_FILE, true, 'PDO::MYSQL_ATTR_READ_DEFAULT_FILE');
|
||||
set_option_and_check(27, PDO::MYSQL_ATTR_READ_DEFAULT_FILE, false, 'PDO::MYSQL_ATTR_READ_DEFAULT_FILE');
|
||||
|
||||
set_option_and_check(30, PDO::MYSQL_ATTR_MAX_BUFFER_SIZE, -1, 'PDO::MYSQL_ATTR_MAX_BUFFER_SIZE', true);
|
||||
set_option_and_check(31, PDO::MYSQL_ATTR_MAX_BUFFER_SIZE, PHP_INT_MAX, 'PDO::MYSQL_ATTR_MAX_BUFFER_SIZE');
|
||||
set_option_and_check(32, PDO::MYSQL_ATTR_MAX_BUFFER_SIZE, 1, 'PDO::MYSQL_ATTR_MAX_BUFFER_SIZE');
|
||||
|
||||
|
||||
} catch (PDOException $e) {
|
||||
printf("[001] %s, [%s] %s\n",
|
||||
$e->getMessage(),
|
||||
(is_object($db)) ? $db->errorCode() : 'n/a',
|
||||
(is_object($db)) ? implode(' ', $db->errorInfo()) : 'n/a');
|
||||
}
|
||||
|
||||
print "done!";
|
||||
?>
|
||||
@@ -0,0 +1,3 @@
|
||||
[001] Expecting default value for 'PDO::MYSQL_ATTR_INIT_COMMAND' of ''/string, getAttribute() reports setting ''/boolean
|
||||
[026] Execting '1'/boolean got ''/boolean' for options 'PDO::MYSQL_ATTR_READ_DEFAULT_FILE'
|
||||
done!
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
|
||||
|
||||
try {
|
||||
|
||||
if ($tmp = MySQLPDOTest::getTempDir()) {
|
||||
|
||||
$file = $tmp . DIRECTORY_SEPARATOR . 'pdomuri.tst';
|
||||
$dsn = MySQLPDOTest::getDSN();
|
||||
$user = PDO_MYSQL_TEST_USER;
|
||||
$pass = PDO_MYSQL_TEST_PASS;
|
||||
$uri = sprintf('uri:file:%s', $file);
|
||||
|
||||
if ($fp = @fopen($file, 'w')) {
|
||||
// ok, great we can create a file with a DSN in it
|
||||
fwrite($fp, $dsn);
|
||||
fclose($fp);
|
||||
clearstatcache();
|
||||
assert(file_exists($file));
|
||||
try {
|
||||
$db = new PDO($uri, $user, $pass);
|
||||
} catch (PDOException $e) {
|
||||
printf("[002] URI=%s, DSN=%s, File=%s (%d bytes, '%s'), %s\n",
|
||||
$uri, $dsn,
|
||||
$file, filesize($file), file_get_contents($file),
|
||||
$e->getMessage());
|
||||
}
|
||||
unlink($file);
|
||||
}
|
||||
|
||||
if ($fp = @fopen($file, 'w')) {
|
||||
fwrite($fp, sprintf('mysql:dbname=letshopeinvalid;%s%s',
|
||||
chr(0), $dsn));
|
||||
fclose($fp);
|
||||
clearstatcache();
|
||||
assert(file_exists($file));
|
||||
try {
|
||||
$db = new PDO($uri, $user, $pass);
|
||||
} catch (PDOException $e) {
|
||||
printf("[003] URI=%s, DSN=%s, File=%s (%d bytes, '%s'), chr(0) test, %s\n",
|
||||
$uri, $dsn,
|
||||
$file, filesize($file), file_get_contents($file),
|
||||
$e->getMessage());
|
||||
}
|
||||
unlink($file);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* TODO: safe mode */
|
||||
|
||||
} catch (PDOException $e) {
|
||||
printf("[001] %s, [%s] %s\n",
|
||||
$e->getMessage(),
|
||||
(is_object($db)) ? $db->errorCode() : 'n/a',
|
||||
(is_object($db)) ? implode(' ', $db->errorInfo()) : 'n/a');
|
||||
}
|
||||
|
||||
print "done!";
|
||||
?>
|
||||
@@ -0,0 +1,5 @@
|
||||
HipHop Warning: %a
|
||||
[002] URI=uri:file:%spdomuri.tst, DSN=mysql%sdbname=%s, File=%spdomuri.tst (%d bytes, 'mysql%sdbname=%s'), invalid data source URI
|
||||
HipHop Warning: %a
|
||||
[003] URI=uri:file:%spdomuri.tst, DSN=mysql%sdbname=%s, File=%spdomuri.tst (%d bytes, 'mysql%sdbname=letshopeinvalid%s'), chr(0) test, invalid data source URI
|
||||
done!
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
|
||||
$db = MySQLPDOTest::factory();
|
||||
|
||||
// autocommit should be on by default
|
||||
if (1 !== ($tmp = $db->getAttribute(PDO::ATTR_AUTOCOMMIT)))
|
||||
printf("[001] Expecting int/1 got %s\n", var_export($tmp, true));
|
||||
|
||||
// lets see if the server agrees to that
|
||||
$row = $db->query('SELECT @@autocommit AS _autocommit')->fetch(PDO::FETCH_ASSOC);
|
||||
if (!$row['_autocommit'])
|
||||
printf("[002] Server autocommit mode should be on, got '%s'\n", var_export($row['_autocommit']));
|
||||
|
||||
// on -> off
|
||||
if (!$db->setAttribute(PDO::ATTR_AUTOCOMMIT, 0))
|
||||
printf("[003] Cannot turn off autocommit\n");
|
||||
|
||||
$row = $db->query('SELECT @@autocommit AS _autocommit')->fetch(PDO::FETCH_ASSOC);
|
||||
if ($row['_autocommit'])
|
||||
printf("[004] Server autocommit mode should be off, got '%s'\n", var_export($row['_autocommit']));
|
||||
|
||||
// PDO thinks autocommit is off, but its manually turned on...
|
||||
if (!$db->query('SET autocommit = 1'))
|
||||
printf("[005] Cannot turn on server autocommit mode, %s\n", var_export($db->errorInfo(), true));
|
||||
|
||||
if (0 !== ($tmp = $db->getAttribute(PDO::ATTR_AUTOCOMMIT)))
|
||||
printf("[006] Expecting int/0 got %s\n", var_export($tmp, true));
|
||||
|
||||
// off -> on
|
||||
if (!$db->query('SET autocommit = 0'))
|
||||
printf("[007] Cannot turn off server autocommit mode, %s\n", var_export($db->errorInfo(), true));
|
||||
|
||||
if (!$db->setAttribute(PDO::ATTR_AUTOCOMMIT, 1))
|
||||
printf("[008] Cannot turn on autocommit\n");
|
||||
|
||||
$row = $db->query('SELECT @@autocommit AS _autocommit')->fetch(PDO::FETCH_ASSOC);
|
||||
if (!$row['_autocommit'])
|
||||
printf("[009] Server autocommit mode should be on, got '%s'\n", var_export($row['_autocommit']));
|
||||
|
||||
if (1 !== ($tmp = $db->getAttribute(PDO::ATTR_AUTOCOMMIT)))
|
||||
printf("[010] Expecting int/1 got %s\n", var_export($tmp, true));
|
||||
|
||||
if (MySQLPDOTest::detect_transactional_mysql_engine($db)) {
|
||||
// nice, we have a transactional engine to play with
|
||||
|
||||
MySQLPDOTest::createTestTable($db, MySQLPDOTest::detect_transactional_mysql_engine($db));
|
||||
$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')");
|
||||
$num++;
|
||||
$row = $db->query('SELECT COUNT(*) AS _num FROM test')->fetch(PDO::FETCH_ASSOC);
|
||||
if ($row['_num'] != $num)
|
||||
printf("[011] Insert has failed, test will fail\n");
|
||||
|
||||
// autocommit is on, no rollback possible
|
||||
$db->query('ROLLBACK');
|
||||
$row = $db->query('SELECT COUNT(*) AS _num FROM test')->fetch(PDO::FETCH_ASSOC);
|
||||
if ($row['_num'] != $num)
|
||||
printf("[012] ROLLBACK should not have undone anything\n");
|
||||
|
||||
if (!$db->setAttribute(PDO::ATTR_AUTOCOMMIT, 0))
|
||||
printf("[013] Cannot turn off autocommit\n");
|
||||
|
||||
$db->query('DELETE FROM test WHERE id = 100');
|
||||
$db->query('ROLLBACK');
|
||||
$row = $db->query('SELECT COUNT(*) AS _num FROM test')->fetch(PDO::FETCH_ASSOC);
|
||||
if ($row['_num'] != $num)
|
||||
printf("[014] ROLLBACK should have undone the DELETE\n");
|
||||
|
||||
$db->query('DELETE FROM test WHERE id = 100');
|
||||
$db->query('COMMIT');
|
||||
$num--;
|
||||
$row = $db->query('SELECT COUNT(*) AS _num FROM test')->fetch(PDO::FETCH_ASSOC);
|
||||
if ($row['_num'] != $num)
|
||||
printf("[015] DELETE should have been committed\n");
|
||||
|
||||
}
|
||||
|
||||
print "done!";
|
||||
?><?php
|
||||
require dirname(__FILE__) . '/mysql_pdo_test.inc';
|
||||
MySQLPDOTest::dropTestTable();
|
||||
?>
|
||||
@@ -0,0 +1 @@
|
||||
done!
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
|
||||
$db = MySQLPDOTest::factory();
|
||||
MySQLPDOTest::createTestTable($db);
|
||||
|
||||
$default = $db->getAttribute(PDO::ATTR_CASE);
|
||||
$known = array(
|
||||
PDO::CASE_LOWER => 'PDO::CASE_LOWER',
|
||||
PDO::CASE_UPPER => 'PDO::CASE_UPPER',
|
||||
PDO::CASE_NATURAL => 'PDO::CASE_NATURAL'
|
||||
);
|
||||
if (!isset($known[$default]))
|
||||
printf("[001] getAttribute(PDO::ATTR_CASE) returns unknown value '%s'\n",
|
||||
var_export($default, true));
|
||||
else
|
||||
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")))
|
||||
printf("[002] %s - %s\n",
|
||||
var_export($db->errorInfo(), true), var_export($db->errorCode(), true));
|
||||
|
||||
var_dump($stmt->fetchAll(PDO::FETCH_BOTH));
|
||||
|
||||
if (true !== $db->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER))
|
||||
printf("[003] Cannot set PDO::ATTR_CASE = PDO::CASE_LOWER, %s - %s\n",
|
||||
var_export($db->errorInfo(), true), var_export($db->errorCode(), true));
|
||||
|
||||
if (($tmp = $db->getAttribute(PDO::ATTR_CASE)) !== PDO::CASE_LOWER)
|
||||
printf("[004] getAttribute(PDO::ATTR_CASE) returns wrong value '%s'\n",
|
||||
var_export($tmp, true));
|
||||
|
||||
if (true === $db->exec('ALTER TABLE test ADD MiXeD CHAR(1)'))
|
||||
printf("[005] Cannot add column %s - %s\n",
|
||||
var_export($db->errorInfo(), true), var_export($db->errorCode(), true));
|
||||
|
||||
if (false === $db->exec('ALTER TABLE test ADD MYUPPER CHAR(1)'))
|
||||
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")))
|
||||
printf("[007] %s - %s\n",
|
||||
var_export($db->errorInfo(), true), var_export($db->errorCode(), true));
|
||||
|
||||
var_dump($stmt->fetchAll(PDO::FETCH_BOTH));
|
||||
|
||||
if (true !== $db->setAttribute(PDO::ATTR_CASE, PDO::CASE_UPPER))
|
||||
printf("[008] Cannot set PDO::ATTR_CASE = PDO::CASE_UPPER %s - %s\n",
|
||||
var_export($db->errorInfo(), true), var_export($db->errorCode(), true));
|
||||
|
||||
if (($tmp = $db->getAttribute(PDO::ATTR_CASE)) !== PDO::CASE_UPPER)
|
||||
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")))
|
||||
printf("[010] %s - %s\n",
|
||||
var_export($db->errorInfo(), true), var_export($db->errorCode(), true));
|
||||
|
||||
var_dump($stmt->fetchAll(PDO::FETCH_BOTH));
|
||||
|
||||
if (true !== $db->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL))
|
||||
printf("[011] Cannot set PDO::ATTR_CASE = PDO::CASE_NATURAL %s - %s\n",
|
||||
var_export($db->errorInfo(), true), var_export($db->errorCode(), true));
|
||||
|
||||
if (($tmp = $db->getAttribute(PDO::ATTR_CASE)) !== PDO::CASE_NATURAL)
|
||||
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")))
|
||||
printf("[013] %s - %s\n",
|
||||
var_export($db->errorInfo(), true), var_export($db->errorCode(), true));
|
||||
|
||||
var_dump($stmt->fetchAll(PDO::FETCH_BOTH));
|
||||
|
||||
print "done!";
|
||||
?><?php
|
||||
require dirname(__FILE__) . '/mysql_pdo_test.inc';
|
||||
MySQLPDOTest::dropTestTable();
|
||||
?>
|
||||
@@ -0,0 +1,132 @@
|
||||
%unicode|string%(15) "PDO::CASE_LOWER"
|
||||
array(2) {
|
||||
[0]=>
|
||||
array(6) {
|
||||
[%u|b%"id"]=>
|
||||
%unicode|string%(1) "1"
|
||||
[0]=>
|
||||
%unicode|string%(1) "1"
|
||||
[%u|b%"id_upper"]=>
|
||||
%unicode|string%(1) "1"
|
||||
[1]=>
|
||||
%unicode|string%(1) "1"
|
||||
[%u|b%"label"]=>
|
||||
%unicode|string%(1) "a"
|
||||
[2]=>
|
||||
%unicode|string%(1) "a"
|
||||
}
|
||||
[1]=>
|
||||
array(6) {
|
||||
[%u|b%"id"]=>
|
||||
%unicode|string%(1) "2"
|
||||
[0]=>
|
||||
%unicode|string%(1) "2"
|
||||
[%u|b%"id_upper"]=>
|
||||
%unicode|string%(1) "2"
|
||||
[1]=>
|
||||
%unicode|string%(1) "2"
|
||||
[%u|b%"label"]=>
|
||||
%unicode|string%(1) "b"
|
||||
[2]=>
|
||||
%unicode|string%(1) "b"
|
||||
}
|
||||
}
|
||||
array(2) {
|
||||
[0]=>
|
||||
array(10) {
|
||||
[%u|b%"id"]=>
|
||||
%unicode|string%(1) "1"
|
||||
[0]=>
|
||||
%unicode|string%(1) "1"
|
||||
[%u|b%"id_upper"]=>
|
||||
%unicode|string%(1) "1"
|
||||
[1]=>
|
||||
%unicode|string%(1) "1"
|
||||
[%u|b%"label"]=>
|
||||
%unicode|string%(1) "a"
|
||||
[2]=>
|
||||
%unicode|string%(1) "a"
|
||||
[%u|b%"mixed"]=>
|
||||
NULL
|
||||
[3]=>
|
||||
NULL
|
||||
[%u|b%"myupper"]=>
|
||||
NULL
|
||||
[4]=>
|
||||
NULL
|
||||
}
|
||||
[1]=>
|
||||
array(10) {
|
||||
[%u|b%"id"]=>
|
||||
%unicode|string%(1) "2"
|
||||
[0]=>
|
||||
%unicode|string%(1) "2"
|
||||
[%u|b%"id_upper"]=>
|
||||
%unicode|string%(1) "2"
|
||||
[1]=>
|
||||
%unicode|string%(1) "2"
|
||||
[%u|b%"label"]=>
|
||||
%unicode|string%(1) "b"
|
||||
[2]=>
|
||||
%unicode|string%(1) "b"
|
||||
[%u|b%"mixed"]=>
|
||||
NULL
|
||||
[3]=>
|
||||
NULL
|
||||
[%u|b%"myupper"]=>
|
||||
NULL
|
||||
[4]=>
|
||||
NULL
|
||||
}
|
||||
}
|
||||
array(1) {
|
||||
[0]=>
|
||||
array(10) {
|
||||
[%u|b%"ID"]=>
|
||||
%unicode|string%(1) "1"
|
||||
[0]=>
|
||||
%unicode|string%(1) "1"
|
||||
[%u|b%"LABEL"]=>
|
||||
%unicode|string%(1) "a"
|
||||
[1]=>
|
||||
%unicode|string%(1) "a"
|
||||
[%u|b%"MIXED"]=>
|
||||
NULL
|
||||
[2]=>
|
||||
NULL
|
||||
[%u|b%"MYUPPER"]=>
|
||||
NULL
|
||||
[3]=>
|
||||
NULL
|
||||
[%u|b%"LOWER"]=>
|
||||
NULL
|
||||
[4]=>
|
||||
NULL
|
||||
}
|
||||
}
|
||||
array(1) {
|
||||
[0]=>
|
||||
array(10) {
|
||||
[%u|b%"id"]=>
|
||||
%unicode|string%(1) "1"
|
||||
[0]=>
|
||||
%unicode|string%(1) "1"
|
||||
[%u|b%"label"]=>
|
||||
%unicode|string%(1) "a"
|
||||
[1]=>
|
||||
%unicode|string%(1) "a"
|
||||
[%u|b%"MiXeD"]=>
|
||||
NULL
|
||||
[2]=>
|
||||
NULL
|
||||
[%u|b%"MYUPPER"]=>
|
||||
NULL
|
||||
[3]=>
|
||||
NULL
|
||||
[%u|b%"ID"]=>
|
||||
%unicode|string%(1) "1"
|
||||
[4]=>
|
||||
%unicode|string%(1) "1"
|
||||
}
|
||||
}
|
||||
done!
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
|
||||
$db = MySQLPDOTest::factory();
|
||||
|
||||
assert(('' == $db->errorCode()) || ('00000' == $db->errorCode()));
|
||||
|
||||
$version = $db->getAttribute(PDO::ATTR_CLIENT_VERSION);
|
||||
|
||||
// No more constraints - mysqlnd and libmysql return different strings at least
|
||||
// with mysqli. Return type check is already performed in the generic test.
|
||||
// According to the manual we should get an int but as of today we do get a string...
|
||||
if ('' == $version)
|
||||
printf("[001] Client version must not be empty\n");
|
||||
|
||||
|
||||
// Read-only
|
||||
if (false !== $db->setAttribute(PDO::ATTR_CLIENT_VERSION, '1.0'))
|
||||
printf("[002] Wonderful, I can change the client version!\n");
|
||||
|
||||
$new_version = $db->getAttribute(PDO::ATTR_CLIENT_VERSION);
|
||||
if ($new_version !== $version)
|
||||
printf("[003] Did we change it from '%s' to '%s'?\n", $version, $new_version);
|
||||
|
||||
print "done!";
|
||||
?>
|
||||
@@ -0,0 +1 @@
|
||||
done!
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
|
||||
$db = MySQLPDOTest::factory();
|
||||
|
||||
$status = $db->getAttribute(PDO::ATTR_CONNECTION_STATUS);
|
||||
if (ini_get('unicode.semantics')) {
|
||||
if (!is_unicode($status))
|
||||
printf("[001] Expecting unicode, got '%s'\n", var_export($status, true));
|
||||
} else {
|
||||
if (!is_string($status))
|
||||
printf("[002] Expecting string, got '%s'\n", var_export($status, true));
|
||||
}
|
||||
|
||||
if ('' == $status)
|
||||
printf("[003] Connection status string must not be empty\n");
|
||||
|
||||
if (false !== $db->setAttribute(PDO::ATTR_CONNECTION_STATUS, 'my own connection status'))
|
||||
printf("[004] Changing read only attribute\n");
|
||||
|
||||
$status2 = $db->getAttribute(PDO::ATTR_CONNECTION_STATUS);
|
||||
if ($status !== $status2)
|
||||
printf("[005] Connection status should not have changed\n");
|
||||
|
||||
print "done!";
|
||||
?>
|
||||
@@ -0,0 +1 @@
|
||||
done!
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
|
||||
$db = MySQLPDOTest::factory();
|
||||
|
||||
assert(('' == $db->errorCode()) || ('00000' == $db->errorCode()));
|
||||
|
||||
$name = $db->getAttribute(PDO::ATTR_DRIVER_NAME);
|
||||
var_dump($name);
|
||||
|
||||
if (false !== $db->setAttribute(PDO::ATTR_DRIVER_NAME, 'mydriver'))
|
||||
printf("[001] Wonderful, I can create new PDO drivers!\n");
|
||||
|
||||
$new_name = $db->getAttribute(PDO::ATTR_DRIVER_NAME);
|
||||
if ($name != $new_name)
|
||||
printf("[002] Did we change it from '%s' to '%s'?\n", $name, $new_name);
|
||||
|
||||
print "done!";
|
||||
?>
|
||||
@@ -0,0 +1,2 @@
|
||||
%unicode|string%(5) "mysql"
|
||||
done!
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
|
||||
$db = MySQLPDOTest::factory();
|
||||
MySQLPDOTest::createTestTable($db);
|
||||
|
||||
$db->setAttribute(PDO::ATTR_FETCH_TABLE_NAMES, 1);
|
||||
$stmt = $db->query('SELECT label FROM test LIMIT 1');
|
||||
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
|
||||
$stmt->closeCursor();
|
||||
|
||||
$db->setAttribute(PDO::ATTR_FETCH_TABLE_NAMES, 0);
|
||||
$stmt = $db->query('SELECT label FROM test LIMIT 1');
|
||||
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
|
||||
$stmt->closeCursor();
|
||||
|
||||
print "done!";
|
||||
?>
|
||||
@@ -0,0 +1,15 @@
|
||||
array(1) {
|
||||
[0]=>
|
||||
array(1) {
|
||||
[%u|b%"test.label"]=>
|
||||
%unicode|string%(1) "a"
|
||||
}
|
||||
}
|
||||
array(1) {
|
||||
[0]=>
|
||||
array(1) {
|
||||
[%u|b%"label"]=>
|
||||
%unicode|string%(1) "a"
|
||||
}
|
||||
}
|
||||
done!
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
|
||||
|
||||
function try_buffer_size($offset, $buffer_size) {
|
||||
|
||||
try {
|
||||
|
||||
$dsn = MySQLPDOTest::getDSN();
|
||||
$user = PDO_MYSQL_TEST_USER;
|
||||
$pass = PDO_MYSQL_TEST_PASS;
|
||||
|
||||
/* unsigned overflow possible ? */
|
||||
$db = new PDO($dsn, $user, $pass,
|
||||
array(
|
||||
PDO::MYSQL_ATTR_MAX_BUFFER_SIZE => $buffer_size,
|
||||
/* buffer is only relevant with native PS */
|
||||
PDO::MYSQL_ATTR_DIRECT_QUERY => 0,
|
||||
PDO::ATTR_EMULATE_PREPARES => 0,
|
||||
));
|
||||
|
||||
$db->exec('DROP TABLE IF EXISTS test');
|
||||
$db->exec(sprintf('CREATE TABLE test(id INT, val LONGBLOB) ENGINE = %s', PDO_MYSQL_TEST_ENGINE));
|
||||
|
||||
// 10 * (10 * 1024) = 10 * (10 * 1k) = 100k
|
||||
$db->exec('INSERT INTO test(id, val) VALUES (1, REPEAT("01234567890", 10240))');
|
||||
|
||||
$stmt = $db->prepare('SELECT id, val FROM test');
|
||||
$stmt->execute();
|
||||
|
||||
$id = $val = NULL;
|
||||
$stmt->bindColumn(1, $id);
|
||||
$stmt->bindColumn(2, $val);
|
||||
while ($row = $stmt->fetch(PDO::FETCH_BOUND)) {
|
||||
printf("[%03d] id = %d, val = %s... (length: %d)\n",
|
||||
$offset, $id, substr($val, 0, 10), strlen($val));
|
||||
}
|
||||
$db->exec('DROP TABLE IF EXISTS test');
|
||||
|
||||
} catch (PDOException $e) {
|
||||
printf("[%03d] %s, [%s] %s\n",
|
||||
$offset,
|
||||
$e->getMessage(),
|
||||
(is_object($db)) ? $db->errorCode() : 'n/a',
|
||||
(is_object($db)) ? implode(' ', $db->errorInfo()) : 'n/a');
|
||||
}
|
||||
}
|
||||
|
||||
try_buffer_size(1, -1);
|
||||
try_buffer_size(2, 1000);
|
||||
try_buffer_size(3, NULL);
|
||||
try_buffer_size(4, 2000);
|
||||
|
||||
print "done!";
|
||||
?><?php
|
||||
require dirname(__FILE__) . '/mysql_pdo_test.inc';
|
||||
$db = MySQLPDOTest::factory();
|
||||
$db->exec('DROP TABLE IF EXISTS test');
|
||||
?>
|
||||
@@ -0,0 +1,5 @@
|
||||
[001] id = 1, val = 0123456789... (length: %d)
|
||||
[002] id = 1, val = 0123456789... (length: 1000)
|
||||
[003] id = 1, val = 0123456789... (length: %d)
|
||||
[004] id = 1, val = 0123456789... (length: 2000)
|
||||
done!
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
|
||||
$db = MySQLPDOTest::factory();
|
||||
MySQLPDOTest::createTestTable($db);
|
||||
|
||||
$tmp = array();
|
||||
if (false !== @$db->setAttribute(PDO::ATTR_ORACLE_NULLS, $tmp))
|
||||
printf("[001] Maybe PDO could indicate that this is not a proper way of setting ATTR_ORACLE_NULLS...\n");
|
||||
|
||||
$tmp = new stdClass();
|
||||
if (false !== @$db->setAttribute(PDO::ATTR_ORACLE_NULLS, $tmp));
|
||||
printf("[002] Maybe PDO could indicate that this is not a proper way of setting ATTR_ORACLE_NULLS...\n");
|
||||
|
||||
if (false !== @$db->setAttribute(PDO::ATTR_ORACLE_NULLS, 'pdo'))
|
||||
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");
|
||||
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");
|
||||
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
|
||||
|
||||
$db->setAttribute(PDO::ATTR_ORACLE_NULLS, 1);
|
||||
$stmt = $db->query('SELECT VERSION() as _version');
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
if ((int)substr($row['_version'], 0, 1) >= 5)
|
||||
$have_procedures = true;
|
||||
else
|
||||
$have_procedures = false;
|
||||
|
||||
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0);
|
||||
$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;"))) {
|
||||
// requires MySQL 5+
|
||||
$stmt = $db->prepare('CALL p()');
|
||||
$stmt->execute();
|
||||
$expected = array(
|
||||
array(
|
||||
"z" => NULL,
|
||||
"a" => NULL,
|
||||
"b" => " ",
|
||||
"c" => NULL,
|
||||
"d" => " d",
|
||||
"e" => " e",
|
||||
),
|
||||
);
|
||||
do {
|
||||
$tmp = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
if ($tmp != $expected) {
|
||||
printf("[004] Expecting %s got %s\n",
|
||||
var_export($expected, true), var_export($tmp, true));
|
||||
}
|
||||
} while ($stmt->nextRowset());
|
||||
|
||||
$stmt->execute();
|
||||
do {
|
||||
$tmp = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
if ($tmp != $expected) {
|
||||
printf("[005] Expecting %s got %s\n",
|
||||
var_export($expected, true), var_export($tmp, true));
|
||||
}
|
||||
} while ($stmt->nextRowset());
|
||||
|
||||
}
|
||||
|
||||
if ($have_procedures)
|
||||
@$db->exec('DROP PROCEDURE IF EXISTS p');
|
||||
|
||||
print "done!";
|
||||
?>
|
||||
@@ -0,0 +1,37 @@
|
||||
[002] Maybe PDO could indicate that this is not a proper way of setting ATTR_ORACLE_NULLS...
|
||||
[003] Maybe PDO could indicate that this is not a proper way of setting ATTR_ORACLE_NULLS...
|
||||
array(1) {
|
||||
[0]=>
|
||||
array(6) {
|
||||
[%u|b%"z"]=>
|
||||
NULL
|
||||
[%u|b%"a"]=>
|
||||
NULL
|
||||
[%u|b%"b"]=>
|
||||
%unicode|string%(1) " "
|
||||
[%u|b%"c"]=>
|
||||
NULL
|
||||
[%u|b%"d"]=>
|
||||
%unicode|string%(2) " d"
|
||||
[%u|b%"e"]=>
|
||||
%unicode|string%(3) "%se"
|
||||
}
|
||||
}
|
||||
array(1) {
|
||||
[0]=>
|
||||
array(6) {
|
||||
[%u|b%"z"]=>
|
||||
NULL
|
||||
[%u|b%"a"]=>
|
||||
%unicode|string%(0) ""
|
||||
[%u|b%"b"]=>
|
||||
%unicode|string%(1) " "
|
||||
[%u|b%"c"]=>
|
||||
%unicode|string%(0) ""
|
||||
[%u|b%"d"]=>
|
||||
%unicode|string%(2) " d"
|
||||
[%u|b%"e"]=>
|
||||
%unicode|string%(3) "%se"
|
||||
}
|
||||
}
|
||||
done!
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
|
||||
$db = MySQLPDOTest::factory();
|
||||
var_dump($db->getAttribute(PDO::ATTR_PREFETCH));
|
||||
var_dump($db->setAttribute(PDO::ATTR_PREFETCH, true));
|
||||
print "done!";
|
||||
@@ -0,0 +1,4 @@
|
||||
HipHop Warning: %a
|
||||
bool(false)
|
||||
bool(false)
|
||||
done!
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
|
||||
$db = MySQLPDOTest::factory();
|
||||
|
||||
assert(('' == $db->errorCode()) || ('00000' == $db->errorCode()));
|
||||
|
||||
$info = $db->getAttribute(PDO::ATTR_SERVER_INFO);
|
||||
if ('' == $info)
|
||||
printf("[001] Server info must not be empty\n");
|
||||
|
||||
// Read-only?
|
||||
if (false !== $db->setAttribute(PDO::ATTR_SERVER_INFO, 'new uptime: 0s'))
|
||||
printf("[002] Wonderful, I can change the client version!\n");
|
||||
|
||||
$new_info = $db->getAttribute(PDO::ATTR_SERVER_INFO);
|
||||
if (soundex($new_info) != soundex($info))
|
||||
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%'"))
|
||||
printf("[004] Cannot run SHOW STATUS, [%s]\n", $db->errorCode());
|
||||
else {
|
||||
if (!$row = $stmt->fetch(PDO::FETCH_NUM))
|
||||
printf("[005] Unable to fetch uptime, [%s]\n", $db->errorCode());
|
||||
else
|
||||
$uptime = $row[1];
|
||||
$stmt->closeCursor();
|
||||
}
|
||||
|
||||
if (!preg_match('/Uptime/i', $info))
|
||||
printf("[006] Can't find uptime in server info '%s'\n", $info);
|
||||
|
||||
if (isset($uptime) && !preg_match(sprintf('/Uptime: %d/i', $uptime), $info))
|
||||
printf("[007] SHOW STATUS and server info have reported a different uptime, please check. Server info: '%s', SHOW STATUS: '%s'\n", $info, $uptime);
|
||||
|
||||
print "done!";
|
||||
@@ -0,0 +1 @@
|
||||
done!
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
|
||||
$db = MySQLPDOTest::factory();
|
||||
|
||||
assert(('' == $db->errorCode()) || ('00000' == $db->errorCode()));
|
||||
|
||||
$version = $db->getAttribute(PDO::ATTR_SERVER_VERSION);
|
||||
if ('' == $version)
|
||||
printf("[001] Server version must not be empty\n");
|
||||
|
||||
// Ideally the server version would be an integer - as documented but BC break!
|
||||
// If its a version string it should be of the format \d+\.\d+\.\d+.*
|
||||
|
||||
if (is_string($version)) {
|
||||
// Its not an int like documented but a string - maybe for BC reasons...
|
||||
if (!preg_match('/(\d+)\.(\d+)\.(\d+)(.*)/', $version, $matches))
|
||||
printf("[002] Client version string seems wrong, got '%s'\n", $version);
|
||||
else {
|
||||
// Difficult to define any meaningful constraints
|
||||
// A possible better check would be calling mysqli_get_server_version() and
|
||||
// comparing what we get. However, mysqli_get_server_version() needs a mysqli handle
|
||||
// for which in turn one needs to parse the PDO test environment variables
|
||||
// for connection parameter...
|
||||
if ($matches[1] < 3)
|
||||
printf("[003] Strange major version: '%s'. Should be more than 3\n", $matches[1]);
|
||||
if ($matches[2] < 0)
|
||||
printf("[004] Minor version should be at least 0, got '%s'\n", $matches[2]);
|
||||
if ($matches[3] < 0)
|
||||
printf("[005] Sub version should be at least 0, got '%s'\n", $matches[2]);
|
||||
}
|
||||
} else if (is_int($version)) {
|
||||
// Lets accept also int if it follows the rules from the original MYSQL C API
|
||||
$major = floor($version / 10000);
|
||||
$minor = floor(($version - ($main * 10000)) / 100);
|
||||
$sub = $version - ($main * 10000) - ($minor * 100);
|
||||
if ($major < 3)
|
||||
printf("[006] Strange major version: '%s'. Should be more than 3\n", $major);
|
||||
if ($minor < 0)
|
||||
printf("[007] Minor version should be at least 0, got '%s'\n", $minor);
|
||||
if ($sub < 0)
|
||||
printf("[008] Sub version should be at least 0, got '%s'\n", $sub);
|
||||
}
|
||||
|
||||
// Read-only?
|
||||
if (false !== $db->setAttribute(PDO::ATTR_CLIENT_VERSION, '1.0'))
|
||||
printf("[009] Wonderful, I can change the client version!\n");
|
||||
|
||||
$new_version = $db->getAttribute(PDO::ATTR_SERVER_VERSION);
|
||||
if ($new_version !== $version)
|
||||
printf("[010] Did we change it from '%s' to '%s'?\n", $version, $new_version);
|
||||
|
||||
print "done!";
|
||||
?>
|
||||
@@ -0,0 +1 @@
|
||||
done!
|
||||
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
|
||||
$db = MySQLPDOTest::factory();
|
||||
MySQLPDOTest::createTestTable($db);
|
||||
|
||||
$default = $db->getAttribute(PDO::ATTR_STATEMENT_CLASS);
|
||||
var_dump($default);
|
||||
|
||||
if (false !== ($tmp = @$db->setAttribute(PDO::ATTR_STATEMENT_CLASS)))
|
||||
printf("[001] Expecting boolean/false got %s\n", var_export($tmp, true));
|
||||
|
||||
if (false !== ($tmp = @$db->setAttribute(PDO::ATTR_STATEMENT_CLASS, 'foo')))
|
||||
printf("[002] Expecting boolean/false got %s\n", var_export($tmp, true));
|
||||
|
||||
if (false !== ($tmp = @$db->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('classname'))))
|
||||
printf("[003] Expecting boolean/false got %s\n", var_export($tmp, true));
|
||||
|
||||
// unknown class
|
||||
if (false !== ($tmp = $db->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('classname', array()))))
|
||||
printf("[004] Expecting boolean/false got %s\n", var_export($tmp, true));
|
||||
|
||||
// class not derived from PDOStatement
|
||||
class myclass {
|
||||
function __construct() {
|
||||
printf("myclass\n");
|
||||
}
|
||||
}
|
||||
if (false !== ($tmp = $db->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('myclass', array()))))
|
||||
printf("[005] Expecting boolean/false got %s\n", var_export($tmp, true));
|
||||
|
||||
// public constructor not allowed
|
||||
class mystatement extends PDOStatement {
|
||||
public function __construct() {
|
||||
printf("mystatement\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (false !== ($tmp = $db->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('mystatement', array()))))
|
||||
printf("[006] Expecting boolean/false got %s\n", var_export($tmp, true));
|
||||
|
||||
// ... but a public destructor is allowed
|
||||
class mystatement2 extends PDOStatement {
|
||||
public function __destruct() {
|
||||
printf("mystatement\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (true !== ($tmp = $db->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('mystatement2', array()))))
|
||||
printf("[007] Expecting boolean/true got %s\n", var_export($tmp, true));
|
||||
|
||||
// private constructor
|
||||
class mystatement3 extends PDOStatement {
|
||||
private function __construct($msg) {
|
||||
printf("mystatement3\n");
|
||||
var_dump($msg);
|
||||
}
|
||||
}
|
||||
if (true !== ($tmp = $db->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('mystatement3', array('param1')))))
|
||||
printf("[008] Expecting boolean/true got %s\n", var_export($tmp, true));
|
||||
|
||||
// private constructor
|
||||
class mystatement4 extends PDOStatement {
|
||||
private function __construct($msg) {
|
||||
printf("%s\n", get_class($this));
|
||||
var_dump($msg);
|
||||
}
|
||||
}
|
||||
if (true !== ($tmp = $db->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('mystatement4', array('param1')))))
|
||||
printf("[008] Expecting boolean/true got %s\n", var_export($tmp, true));
|
||||
|
||||
var_dump($db->getAttribute(PDO::ATTR_STATEMENT_CLASS));
|
||||
$stmt = $db->query('SELECT id, label FROM test ORDER BY id ASC LIMIT 2');
|
||||
|
||||
class mystatement5 extends mystatement4 {
|
||||
public function fetchAll($fetch_style = 1, $column_index = 1, $ctor_args = array()) {
|
||||
return "no data :)";
|
||||
}
|
||||
}
|
||||
|
||||
if (true !== ($tmp = $db->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('mystatement5', array('mystatement5')))))
|
||||
printf("[009] Expecting boolean/true got %s\n", var_export($tmp, true));
|
||||
$stmt = $db->query('SELECT id, label FROM test ORDER BY id ASC LIMIT 2');
|
||||
var_dump($stmt->fetchAll());
|
||||
|
||||
if (true !== ($tmp = $db->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('PDOStatement'))))
|
||||
printf("[010] Expecting boolean/true got %s\n", var_export($tmp, true));
|
||||
|
||||
$stmt = $db->query('SELECT id, label FROM test ORDER BY id ASC LIMIT 1');
|
||||
var_dump($stmt->fetchAll());
|
||||
|
||||
// Yes, this is a fatal error and I want it to fail.
|
||||
abstract class mystatement6 extends mystatement5 {
|
||||
}
|
||||
if (true !== ($tmp = $db->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('mystatement6', array('mystatement6')))))
|
||||
printf("[011] Expecting boolean/true got %s\n", var_export($tmp, true));
|
||||
$stmt = $db->query('SELECT id, label FROM test ORDER BY id ASC LIMIT 1');
|
||||
|
||||
print "done!";
|
||||
?>
|
||||
@@ -0,0 +1,38 @@
|
||||
array(1) {
|
||||
[0]=>
|
||||
%unicode|string%(12) "PDOStatement"
|
||||
}
|
||||
HipHop Warning: %a
|
||||
HipHop Warning: %a
|
||||
HipHop Warning: %a
|
||||
HipHop Warning: %a
|
||||
HipHop Warning: %a
|
||||
HipHop Warning: %a
|
||||
array(2) {
|
||||
[0]=>
|
||||
%unicode|string%(12) "mystatement4"
|
||||
[1]=>
|
||||
array(1) {
|
||||
[0]=>
|
||||
%unicode|string%(6) "param1"
|
||||
}
|
||||
}
|
||||
mystatement4
|
||||
%unicode|string%(6) "param1"
|
||||
mystatement5
|
||||
%unicode|string%(12) "mystatement5"
|
||||
%unicode|string%(10) "no data :)"
|
||||
array(1) {
|
||||
[0]=>
|
||||
array(4) {
|
||||
[%u|b%"id"]=>
|
||||
%unicode|string%(1) "1"
|
||||
[0]=>
|
||||
%unicode|string%(1) "1"
|
||||
[%u|b%"label"]=>
|
||||
%unicode|string%(1) "a"
|
||||
[1]=>
|
||||
%unicode|string%(1) "a"
|
||||
}
|
||||
}
|
||||
HipHop Fatal error: %a
|
||||
@@ -0,0 +1,174 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
|
||||
$db = MySQLPDOTest::factory();
|
||||
MySQLPDOTest::createTestTable($db, MySQLPDOTest::detect_transactional_mysql_engine($db));
|
||||
|
||||
if (1 !== $db->getAttribute(PDO::ATTR_AUTOCOMMIT))
|
||||
printf("[001] Autocommit should be on by default\n");
|
||||
|
||||
if (false == $db->beginTransaction())
|
||||
printf("[002] Cannot start a transaction, [%s] [%s]\n",
|
||||
$db->errorCode(), implode(' ', $db->errorInfo()));
|
||||
|
||||
if (1 !== $db->getAttribute(PDO::ATTR_AUTOCOMMIT))
|
||||
printf("[003] Autocommit should be on by default, beginTransaction() shall not impact it\n");
|
||||
|
||||
if (0 == $db->exec('DELETE FROM test'))
|
||||
printf("[004] No rows deleted, can't be true.\n");
|
||||
|
||||
/* This is the PDO way to close a connection */
|
||||
$db = null;
|
||||
$db = MySQLPDOTest::factory();
|
||||
|
||||
/* Autocommit was off - by definition. Commit was not issued. DELETE should have been rolled back. */
|
||||
if (!($stmt = $db->query('SELECT id, label FROM test ORDER BY id ASC')))
|
||||
printf("[005] [%s] %s\n", $db->errorCode(), implode(' ', $db->errorInfo()));
|
||||
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
var_dump($row);
|
||||
|
||||
if (!$db->beginTransaction())
|
||||
printf("[006] [%s] %s\n", $db->errorCode(), implode(' ', $db->errorInfo()));
|
||||
|
||||
if (1 !== $db->exec(sprintf('DELETE FROM test WHERE id = %d', $row['id'])))
|
||||
printf("[007] DELETE should have indicated 1 deleted row, [%s] %s\n", $db->errorCode(), implode(' ', $db->errorInfo()));
|
||||
|
||||
if (!$db->commit())
|
||||
printf("[008] [%s] %s\n", $db->errorCode(), implode(' ', $db->errorInfo()));
|
||||
|
||||
if (1 !== $db->getAttribute(PDO::ATTR_AUTOCOMMIT))
|
||||
printf("[009] Autocommit should be on after commit()\n");
|
||||
|
||||
if (!($stmt = $db->query(sprintf('SELECT id, label FROM test WHERE id = %d', $row['id']))))
|
||||
printf("[010] [%s] %s\n", $db->errorCode(), implode(' ', $db->errorInfo()));
|
||||
|
||||
var_dump($stmt->fetch(PDO::FETCH_ASSOC));
|
||||
|
||||
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']));
|
||||
|
||||
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()));
|
||||
|
||||
$new_row1 = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
var_dump($new_row1);
|
||||
|
||||
if (!$db->commit())
|
||||
printf("[013] [%s] %s\n", $db->errorCode(), implode(' ', $db->errorInfo()));
|
||||
|
||||
if (!($stmt = $db->query(sprintf('SELECT id, label FROM test WHERE id = %d', $row['id']))))
|
||||
printf("[014] [%s] %s\n", $db->errorCode(), implode(' ', $db->errorInfo()));
|
||||
|
||||
$new_row2 = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
if ($new_row1 != $new_row2) {
|
||||
printf("[015] Results must not differ!\n");
|
||||
var_dump($new_row1);
|
||||
var_dump($new_row2);
|
||||
}
|
||||
|
||||
if (!$db->beginTransaction())
|
||||
printf("[016] [%s] %s\n", $db->errorCode(), implode(' ', $db->errorInfo()));
|
||||
|
||||
if (1 !== $db->exec(sprintf('DELETE FROM test WHERE id = %d', $row['id'])))
|
||||
printf("[017] DELETE should have indicated 1 deleted row, [%s] %s\n", $db->errorCode(), implode(' ', $db->errorInfo()));
|
||||
|
||||
if (!$db->rollback())
|
||||
printf("[018] [%s] %s\n", $db->errorCode(), implode(' ', $db->errorInfo()));
|
||||
|
||||
if (1 !== $db->getAttribute(PDO::ATTR_AUTOCOMMIT))
|
||||
printf("[019] Autocommit should be on after rollback\n");
|
||||
|
||||
if (!($stmt = $db->query(sprintf('SELECT id, label FROM test WHERE id = %d', $row['id']))))
|
||||
printf("[020] [%s] %s\n", $db->errorCode(), implode(' ', $db->errorInfo()));
|
||||
|
||||
$new_row2 = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
if ($new_row1 != $new_row2) {
|
||||
printf("[021] Results must not differ!\n");
|
||||
var_dump($new_row1);
|
||||
var_dump($new_row2);
|
||||
}
|
||||
|
||||
// now, lets check the server variables
|
||||
if (!($stmt = $db->query('SELECT @@autocommit as auto_commit')))
|
||||
printf("[022] [%s] %s\n", $db->errorCode(), implode(' ', $db->errorInfo()));
|
||||
|
||||
$tmp = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
if ($tmp['auto_commit'] != 1)
|
||||
printf("[023] MySQL Server should indicate autocommit mode, expecting 1, got '%s', [%d] %s\n",
|
||||
$tmp['auto_commit'], $stmt->errorCode(), $stmt->errorInfo());
|
||||
|
||||
if (!$db->beginTransaction())
|
||||
printf("[024] [%s] %s\n", $db->errorCode(), implode(' ', $db->errorInfo()));
|
||||
|
||||
if (!($stmt = $db->query('SELECT @@autocommit as auto_commit')))
|
||||
printf("[025] [%s] %s\n", $db->errorCode(), implode(' ', $db->errorInfo()));
|
||||
|
||||
$tmp = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
if ($tmp['auto_commit'] != 0)
|
||||
printf("[026] Autocommit mode of the MySQL Server should be off, got '%s', [%d] %s\n",
|
||||
$tmp['auto_commit'], $stmt->errorCode(), trim(implode(' ', $stmt->errorInfo())));
|
||||
|
||||
$db->commit();
|
||||
// Now we should be back to autocommit - we've issues a commit
|
||||
if ($tmp['auto_commit'] != 1)
|
||||
printf("[027] MySQL Server should indicate autocommit mode, expecting 1, got '%s', [%d] %s\n",
|
||||
$tmp['auto_commit'], $stmt->errorCode(), $stmt->errorInfo());
|
||||
|
||||
// Turn off autocommit using a server variable
|
||||
$db->exec('SET @@autocommit = 0');
|
||||
if (1 === $db->getAttribute(PDO::ATTR_AUTOCOMMIT))
|
||||
printf("[028] I'm confused, how can autocommit be on? Didn't I say I want to manually control transactions?\n");
|
||||
|
||||
if (!$db->beginTransaction())
|
||||
printf("[029] Cannot start a transaction, [%d] %s\n",
|
||||
$db->errorCode(), implode(' ', $db->errorInfo()));
|
||||
|
||||
try {
|
||||
if (false !== $db->beginTransaction()) {
|
||||
printf("[030] No false and no exception - that's wrong.\n");
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
assert($e->getMessage() != '');
|
||||
}
|
||||
|
||||
// TODO: What about an engine that does not support transactions?
|
||||
$db = MySQLPDOTest::factory();
|
||||
MySQLPDOTest::createTestTable($db, 'MyISAM');
|
||||
|
||||
if (false == $db->beginTransaction())
|
||||
printf("[031] Cannot start a transaction, [%s] [%s]\n",
|
||||
$db->errorCode(), implode(' ', $db->errorInfo()));
|
||||
|
||||
if (1 !== $db->getAttribute(PDO::ATTR_AUTOCOMMIT))
|
||||
printf("[032] Autocommit should be on my default, beginTransaction() should not change that\n");
|
||||
|
||||
if (0 == $db->exec('DELETE FROM test'))
|
||||
printf("[033] No rows deleted, can't be true.\n");
|
||||
|
||||
if (!$db->commit())
|
||||
printf("[034] [%s] %s\n", $db->errorCode(), implode(' ', $db->errorInfo()));
|
||||
|
||||
if (false == $db->beginTransaction())
|
||||
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')"))
|
||||
printf("[036] Cannot insert data, [%s] [%s]\n",
|
||||
$db->errorCode(), implode(' ', $db->errorInfo()));
|
||||
|
||||
// Should cause a Server warning but no error
|
||||
if (!$db->rollback())
|
||||
printf("[037] [%s] %s\n", $db->errorCode(), implode(' ', $db->errorInfo()));
|
||||
|
||||
var_dump($db->errorCode());
|
||||
|
||||
if (1 != $db->exec('DELETE FROM test'))
|
||||
printf("[038] No rows deleted, can't be true.\n");
|
||||
|
||||
print "done!";
|
||||
?><?php
|
||||
require dirname(__FILE__) . '/mysql_pdo_test.inc';
|
||||
MySQLPDOTest::dropTestTable();
|
||||
?>
|
||||
@@ -0,0 +1,17 @@
|
||||
array(2) {
|
||||
[%u|b%"id"]=>
|
||||
%unicode|string%(1) "1"
|
||||
[%u|b%"label"]=>
|
||||
%unicode|string%(1) "a"
|
||||
}
|
||||
bool(false)
|
||||
array(2) {
|
||||
[%u|b%"id"]=>
|
||||
%unicode|string%(1) "1"
|
||||
[%u|b%"label"]=>
|
||||
%unicode|string%(1) "z"
|
||||
}
|
||||
[026] Autocommit mode of the MySQL Server should be off, got '1', [0] 00000
|
||||
[028] I'm confused, how can autocommit be on? Didn't I say I want to manually control transactions?
|
||||
%unicode|string%(5) "00000"
|
||||
done!
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/* TODO: remove this test after fix and enable the BIT test in pdo_mysql_types.phpt again */
|
||||
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
|
||||
|
||||
function test_type(&$db, $offset, $sql_type, $value, $ret_value = NULL, $pattern = NULL) {
|
||||
|
||||
$db->exec('DROP TABLE IF EXISTS test');
|
||||
$sql = sprintf('CREATE TABLE test(id INT, label %s) ENGINE=%s', $sql_type, MySQLPDOTest::getTableEngine());
|
||||
@$db->exec($sql);
|
||||
if ($db->errorCode() != 0) {
|
||||
// not all MySQL Server versions and/or engines might support the type
|
||||
return true;
|
||||
}
|
||||
|
||||
$stmt = $db->prepare('INSERT INTO test(id, label) VALUES (?, ?)');
|
||||
$stmt->bindValue(1, $offset);
|
||||
$stmt->bindValue(2, $value);
|
||||
if (!$stmt->execute()) {
|
||||
printf("[%03d + 1] INSERT failed, %s\n", $offset, var_export($stmt->errorInfo(), true));
|
||||
return false;
|
||||
}
|
||||
$stmt = $db->query('SELECT id, label FROM test');
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
var_dump($row);
|
||||
var_dump($value);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
$db = MySQLPDOTest::factory();
|
||||
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
|
||||
$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
|
||||
|
||||
test_type($db, 20, 'BIT(8)', 1);
|
||||
|
||||
echo "done!\n";
|
||||
?><?php
|
||||
require dirname(__FILE__) . '/mysql_pdo_test.inc';
|
||||
$db = MySQLPDOTest::factory();
|
||||
$db->exec('DROP TABLE IF EXISTS test');
|
||||
?>
|
||||
@@ -0,0 +1,8 @@
|
||||
array(2) {
|
||||
[%u|b%"id"]=>
|
||||
%unicode|string%(2) "20"
|
||||
[%u|b%"label"]=>
|
||||
%unicode|string%(1) "1"
|
||||
}
|
||||
int(1)
|
||||
done!
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
|
||||
|
||||
$expected = array(
|
||||
'MYSQL_ATTR_USE_BUFFERED_QUERY' => true,
|
||||
'MYSQL_ATTR_LOCAL_INFILE' => true,
|
||||
'MYSQL_ATTR_DIRECT_QUERY' => true,
|
||||
'MYSQL_ATTR_FOUND_ROWS' => true,
|
||||
'MYSQL_ATTR_IGNORE_SPACE' => true,
|
||||
'MYSQL_ATTR_INIT_COMMAND' => true,
|
||||
"MYSQL_ATTR_SSL_KEY" => true,
|
||||
"MYSQL_ATTR_SSL_CERT" => true,
|
||||
"MYSQL_ATTR_SSL_CA" => true,
|
||||
"MYSQL_ATTR_SSL_CAPATH" => true,
|
||||
"MYSQL_ATTR_SSL_CIPHER" => true,
|
||||
"MYSQL_ATTR_COMPRESS" => true,
|
||||
);
|
||||
|
||||
if (!MySQLPDOTest::isPDOMySQLnd()) {
|
||||
$expected['MYSQL_ATTR_MAX_BUFFER_SIZE'] = true;
|
||||
$expected['MYSQL_ATTR_READ_DEFAULT_FILE'] = true;
|
||||
$expected['MYSQL_ATTR_READ_DEFAULT_GROUP'] = true;
|
||||
}
|
||||
|
||||
/*
|
||||
TODO
|
||||
|
||||
MYSQLI_OPT_CONNECT_TIMEOUT != PDO::ATTR_TIMEOUT (integer)
|
||||
Sets the timeout value in seconds for communications with the database.
|
||||
^ Potential BUG, PDO::ATTR_TIMEOUT is used in pdo_mysql_handle_factory
|
||||
|
||||
MYSQLI_SET_CHARSET_NAME -> DSN/charset=<charset_name>
|
||||
^ Undocumented and pitfall for ext/mysqli users
|
||||
|
||||
Assorted mysqlnd settings missing
|
||||
*/
|
||||
$ref = new ReflectionClass('PDO');
|
||||
$constants = $ref->getConstants();
|
||||
$values = array();
|
||||
|
||||
foreach ($constants as $name => $value)
|
||||
if (substr($name, 0, 11) == 'MYSQL_ATTR_') {
|
||||
if (!isset($values[$value]))
|
||||
$values[$value] = array($name);
|
||||
else
|
||||
$values[$value][] = $name;
|
||||
|
||||
if (isset($expected[$name])) {
|
||||
unset($expected[$name]);
|
||||
unset($constants[$name]);
|
||||
}
|
||||
|
||||
} else {
|
||||
unset($constants[$name]);
|
||||
}
|
||||
|
||||
if (!empty($constants)) {
|
||||
printf("[001] Dumping list of unexpected constants\n");
|
||||
var_dump($constants);
|
||||
}
|
||||
|
||||
if (!empty($expected)) {
|
||||
printf("[002] Dumping list of missing constants\n");
|
||||
var_dump($expected);
|
||||
}
|
||||
|
||||
if (!empty($values)) {
|
||||
foreach ($values as $value => $constants) {
|
||||
if (count($constants) > 1) {
|
||||
printf("[003] Several constants share the same value '%s'\n", $value);
|
||||
var_dump($constants);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
print "done!";
|
||||
@@ -0,0 +1 @@
|
||||
done!
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
|
||||
$db = MySQLPDOTest::factory();
|
||||
MySQLPDOTest::createTestTable($db, MySQLPDOTest::detect_transactional_mysql_engine($db));
|
||||
|
||||
try {
|
||||
if (true !== ($tmp = $db->beginTransaction())) {
|
||||
printf("[001] Expecting true, got %s/%s\n", gettype($tmp), $tmp);
|
||||
}
|
||||
|
||||
// DDL will issue an implicit commit
|
||||
$db->exec(sprintf('DROP TABLE IF EXISTS test_commit'));
|
||||
$db->exec(sprintf('CREATE TABLE test_commit(id INT) ENGINE=%s', MySQLPDOTest::detect_transactional_mysql_engine($db)));
|
||||
if (true !== ($tmp = $db->commit())) {
|
||||
printf("[002] No commit allowed? [%s] %s\n",
|
||||
$db->errorCode(), implode(' ', $db->errorInfo()));
|
||||
}
|
||||
|
||||
// pdo_transaction_transitions should check this as well...
|
||||
// ... just to be sure the most basic stuff really works we check it again...
|
||||
if (1 !== ($tmp = $db->getAttribute(PDO::ATTR_AUTOCOMMIT)))
|
||||
printf("[003] According to the manual we should be back to autocommit mode, got %s/%s\n",
|
||||
gettype($tmp), var_export($tmp, true));
|
||||
|
||||
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')");
|
||||
|
||||
if (true !== ($tmp = $db->commit()))
|
||||
printf("[005] No commit allowed? [%s] %s\n",
|
||||
$db->errorCode(), implode(' ', $db->errorInfo()));
|
||||
|
||||
// a weak test without unicode etc. - lets leave that to dedicated tests
|
||||
$stmt = $db->query('SELECT id, label FROM test WHERE id = 100');
|
||||
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
if (!isset($rows[0]['label']) || ($rows[0]['label'] != 'z')) {
|
||||
printf("[006] Record data is strange, dumping rows\n");
|
||||
var_dump($rows);
|
||||
}
|
||||
|
||||
// Ok, lets check MyISAM resp. any other non-transactional engine
|
||||
// pdo_mysql_begin_transaction has more on this, quick check only
|
||||
$db = MySQLPDOTest::factory();
|
||||
MySQLPDOTest::createTestTable($db, 'MyISAM');
|
||||
|
||||
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')");
|
||||
if (true !== ($tmp = $db->commit()))
|
||||
printf("[008] No commit allowed? [%s] %s\n",
|
||||
$db->errorCode(), implode(' ', $db->errorInfo()));
|
||||
|
||||
// a weak test without unicode etc. - lets leave that to dedicated tests
|
||||
$stmt = $db->query('SELECT id, label FROM test WHERE id = 100');
|
||||
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
if (!isset($rows[0]['label']) || ($rows[0]['label'] != 'z')) {
|
||||
printf("[009] Record data is strange, dumping rows\n");
|
||||
var_dump($rows);
|
||||
}
|
||||
|
||||
} catch (PDOException $e) {
|
||||
printf("[002] %s, [%s] %s\n",
|
||||
$e->getMessage(),
|
||||
$db->errorCode(), implode(' ', $db->errorInfo()));
|
||||
}
|
||||
|
||||
print "done!";<?php
|
||||
require dirname(__FILE__) . '/mysql_pdo_test.inc';
|
||||
$db = MySQLPDOTest::factory();
|
||||
$db->exec('DROP TABLE IF EXISTS test_commit');
|
||||
MySQLPDOTest::dropTestTable($db);
|
||||
?>
|
||||
@@ -0,0 +1 @@
|
||||
done!
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
|
||||
|
||||
/* Connect to mysql to determine the current charset so we can diffinate it */
|
||||
$link = MySQLPDOTest::factory();
|
||||
$charset = $link->query("SHOW VARIABLES LIKE 'character_set_connection'")->fetchObject()->value;
|
||||
|
||||
/* Make sure that we don't attempt to set the current character set to make this case useful */
|
||||
$new_charset = ($charset == 'latin1' ? 'ascii' : 'latin1');
|
||||
|
||||
/* Done with the original connection, create a second link to test the character set being defined */
|
||||
unset($link);
|
||||
|
||||
$link = MySQLPDOTest::factory('PDO', false, null, Array('charset' => $new_charset));
|
||||
$conn_charset = $link->query("SHOW VARIABLES LIKE 'character_set_connection'")->fetchObject()->value;
|
||||
|
||||
if ($charset !== $conn_charset) {
|
||||
echo "done!\n";
|
||||
} else {
|
||||
echo "failed!\n";
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1 @@
|
||||
done!
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
|
||||
$db = MySQLPDOTest::factory();
|
||||
MySQLPDOTest::createTestTable($db);
|
||||
|
||||
function check_error($offset, &$obj, $expected = '00000') {
|
||||
|
||||
$code = $obj->errorCode();
|
||||
if (($code != $expected) && (($expected != '00000') && ($code != ''))) {
|
||||
printf("[%03d] Expecting error code '%s' got code '%s'\n",
|
||||
$offset, $expected, $code);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
/*
|
||||
If you create a PDOStatement object through PDO->prepare()
|
||||
or PDO->query() and invoke an error on the statement handle,
|
||||
PDO->errorCode() will not reflect that error. You must call
|
||||
PDOStatement->errorCode() to return the error code for an
|
||||
operation performed on a particular statement handle.
|
||||
*/
|
||||
$code = $db->errorCode();
|
||||
check_error(2, $db);
|
||||
|
||||
$stmt = $db->query('SELECT id, label FROM test');
|
||||
$stmt2 = &$stmt;
|
||||
check_error(3, $db);
|
||||
check_error(4, $stmt);
|
||||
|
||||
$db->exec('DROP TABLE IF EXISTS test');
|
||||
@$stmt->execute();
|
||||
check_error(4, $db);
|
||||
check_error(5, $stmt, '42S02');
|
||||
check_error(6, $stmt2, '42S02');
|
||||
|
||||
$db->exec('DROP TABLE IF EXISTS unknown');
|
||||
@$stmt = $db->query('SELECT id, label FROM unknown');
|
||||
check_error(7, $db, '42S02');
|
||||
|
||||
MySQLPDOTest::createTestTable($db);
|
||||
$stmt = $db->query('SELECT id, label FROM test');
|
||||
check_error(8, $db);
|
||||
check_error(9, $stmt);
|
||||
|
||||
$db2 = &$db;
|
||||
@$db->query('SELECT id, label FROM unknown');
|
||||
check_error(10, $db, '42S02');
|
||||
check_error(11, $db2, '42S02');
|
||||
check_error(12, $stmt);
|
||||
check_error(13, $stmt2);
|
||||
|
||||
// lets hope this is an invalid attribute code
|
||||
$invalid_attr = -1 * PHP_INT_MAX + 3;
|
||||
$tmp = @$db->getAttribute($invalid_attr);
|
||||
check_error(14, $db, 'IM001');
|
||||
check_error(15, $db2, 'IM001');
|
||||
check_error(16, $stmt);
|
||||
check_error(17, $stmt2);
|
||||
|
||||
} catch (PDOException $e) {
|
||||
printf("[001] %s [%s] %s\n",
|
||||
$e->getMessage(), $db->errorCode(), implode(' ', $db->errorInfo()));
|
||||
}
|
||||
|
||||
print "done!";
|
||||
?><?php
|
||||
require dirname(__FILE__) . '/mysql_pdo_test.inc';
|
||||
MySQLPDOTest::dropTestTable();
|
||||
?>
|
||||
@@ -0,0 +1 @@
|
||||
done!
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
|
||||
$db = MySQLPDOTest::factory();
|
||||
MySQLPDOTest::createTestTable($db);
|
||||
|
||||
function check_error($offset, &$obj, $expected = '00000') {
|
||||
$info = $obj->errorInfo();
|
||||
$code = $info[0];
|
||||
|
||||
if (($code != $expected) && (($expected != '00000') && ($code != ''))) {
|
||||
printf("[%03d] Expecting error code '%s' got code '%s'\n",
|
||||
$offset, $expected, $code);
|
||||
}
|
||||
|
||||
if ($expected != '00000') {
|
||||
if (!isset($info[1]) || $info[1] == '')
|
||||
printf("[%03d] Driver-specific error code not set\n", $offset);
|
||||
if (!isset($info[2]) || $info[2] == '')
|
||||
printf("[%03d] Driver-specific error message.not set\n", $offset);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function pdo_mysql_errorinfo($db, $offset) {
|
||||
|
||||
try {
|
||||
|
||||
/*
|
||||
If you create a PDOStatement object through PDO->prepare()
|
||||
or PDO->query() and invoke an error on the statement handle,
|
||||
PDO->errorCode() will not reflect that error. You must call
|
||||
PDOStatement->errorCode() to return the error code for an
|
||||
operation performed on a particular statement handle.
|
||||
*/
|
||||
$code = $db->errorCode();
|
||||
check_error($offset + 2, $db);
|
||||
|
||||
$stmt = $db->query('SELECT id, label FROM test');
|
||||
$stmt2 = &$stmt;
|
||||
check_error($offset + 3, $db);
|
||||
check_error($offset + 4, $stmt);
|
||||
|
||||
$db->exec('DROP TABLE IF EXISTS test');
|
||||
@$stmt->execute();
|
||||
check_error($offset + 5, $db);
|
||||
check_error($offset + 6, $stmt, '42S02');
|
||||
check_error($offset + 7, $stmt2, '42S02');
|
||||
|
||||
@$stmt = $db->query('SELECT id, label FROM unknown');
|
||||
check_error($offset + 8, $db, '42S02');
|
||||
|
||||
MySQLPDOTest::createTestTable($db);
|
||||
$stmt = $db->query('SELECT id, label FROM test');
|
||||
check_error($offset + 9, $db);
|
||||
check_error($offset + 10, $stmt);
|
||||
|
||||
$db2 = &$db;
|
||||
$db->exec('DROP TABLE IF EXISTS unknown');
|
||||
@$db->query('SELECT id, label FROM unknown');
|
||||
check_error($offset + 11, $db, '42S02');
|
||||
check_error($offset + 12, $db2, '42S02');
|
||||
check_error($offset + 13, $stmt);
|
||||
check_error($offset + 14, $stmt2);
|
||||
|
||||
// lets hope this is an invalid attribute code
|
||||
$invalid_attr = -1 * PHP_INT_MAX + 3;
|
||||
$tmp = @$db->getAttribute($invalid_attr);
|
||||
check_error($offset + 15, $db, 'IM001');
|
||||
check_error($offset + 16, $db2, 'IM001');
|
||||
check_error($offset + 17, $stmt);
|
||||
check_error($offset + 18, $stmt2);
|
||||
|
||||
} catch (PDOException $e) {
|
||||
printf("[%03d] %s [%s] %s\n",
|
||||
$offset + 19, $e->getMessage(), $db->errorCode(), implode(' ', $db->errorInfo()));
|
||||
}
|
||||
}
|
||||
|
||||
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1);
|
||||
printf("Emulated Prepared Statements...\n");
|
||||
pdo_mysql_errorinfo($db, 0);
|
||||
|
||||
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0);
|
||||
printf("Native Prepared Statements...\n");
|
||||
pdo_mysql_errorinfo($db, 20);
|
||||
|
||||
print "done!";
|
||||
?><?php
|
||||
require dirname(__FILE__) . '/mysql_pdo_test.inc';
|
||||
MySQLPDOTest::dropTestTable();
|
||||
?>
|
||||
@@ -0,0 +1,7 @@
|
||||
Emulated Prepared Statements...
|
||||
[015] Driver-specific error code not set
|
||||
[015] Driver-specific error message.not set
|
||||
[016] Driver-specific error code not set
|
||||
[016] Driver-specific error message.not set
|
||||
Native Prepared Statements...
|
||||
done!
|
||||
@@ -0,0 +1,169 @@
|
||||
<?php
|
||||
function exec_and_count($offset, &$db, $sql, $exp = NULL) {
|
||||
|
||||
try {
|
||||
|
||||
$ret = $db->exec($sql);
|
||||
if (!is_null($exp) && ($ret !== $exp)) {
|
||||
printf("[%03d] Expecting '%s'/%s got '%s'/%s when running '%s', [%s] %s\n",
|
||||
$offset, $exp, gettype($exp), $ret, gettype($ret), $sql,
|
||||
$db->errorCode(), implode(' ', $db->errorInfo()));
|
||||
return false;
|
||||
}
|
||||
|
||||
} catch (PDOException $e) {
|
||||
printf("[%03d] '%s' has failed, [%s] %s\n",
|
||||
$offset, $sql, $db->errorCode(), implode(' ', $db->errorInfo()));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
|
||||
$db = MySQLPDOTest::factory();
|
||||
MySQLPDOTest::createTestTable($db, MySQLPDOTest::detect_transactional_mysql_engine($db));
|
||||
|
||||
/* affected rows related */
|
||||
try {
|
||||
|
||||
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(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);
|
||||
|
||||
exec_and_count(15, $db, 'THIS IS NOT VALID SQL, I HOPE', false);
|
||||
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);
|
||||
// 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);
|
||||
|
||||
} catch (PDOException $e) {
|
||||
printf("[001] %s, [%s] %s\n",
|
||||
$e->getMessage(),
|
||||
$db->errorCode(), implode(' ', $db->errorInfo()));
|
||||
}
|
||||
|
||||
|
||||
/* CREATE, DROP, CALL SP and SF */
|
||||
if (MySQLPDOTest::getServerVersion($db) > 50000) {
|
||||
// let's try to play with stored procedures
|
||||
try {
|
||||
$ignore_exception = true;
|
||||
exec_and_count(18, $db, 'DROP PROCEDURE IF EXISTS p', 0);
|
||||
exec_and_count(19, $db, 'CREATE PROCEDURE p(OUT ver_param VARCHAR(255)) BEGIN SELECT VERSION() INTO ver_param; END;', 0);
|
||||
// we got this far without problems. If there's an issue from now on, its a failure
|
||||
$ignore_exception = false;
|
||||
exec_and_count(20, $db, 'CALL p(@version)', 0);
|
||||
$stmt = $db->query('SELECT @version AS p_version');
|
||||
$tmp = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
if (count($tmp) > 1 || !isset($tmp[0]['p_version'])) {
|
||||
printf("[022] Data seems wrong, dumping\n");
|
||||
var_dump($tmp);
|
||||
} else {
|
||||
$p_version = $tmp[0]['p_version'];
|
||||
}
|
||||
|
||||
$stmt = $db->query('SELECT VERSION() AS _version');
|
||||
$tmp = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
if (count($tmp) > 1 || !isset($tmp[0]['_version'])) {
|
||||
printf("[023] Data seems wrong, dumping\n");
|
||||
var_dump($tmp);
|
||||
} else {
|
||||
if ($p_version !== $tmp[0]['_version']) {
|
||||
printf("[024] Found different version strings, SP returned '%s'/%s, SELECT returned '%s'/%s\n",
|
||||
$p_version, gettype($p_version),
|
||||
$tmp[0]['_version'], gettype($tmp[0]['_version']));
|
||||
}
|
||||
}
|
||||
exec_and_count(25, $db, 'DROP PROCEDURE IF EXISTS p', 0);
|
||||
|
||||
} catch (PDOException $e) {
|
||||
// ignore it, we might not have sufficient permissions
|
||||
if (!$ignore_exception)
|
||||
printf("[021] %s, [%s] %s\n",
|
||||
$e->getMessage(),
|
||||
$db->errorCode(), implode(' ', $db->errorInfo()));
|
||||
}
|
||||
|
||||
// stored function
|
||||
try {
|
||||
$ignore_exception = true;
|
||||
exec_and_count(27, $db, 'DROP FUNCTION IF EXISTS f', 0);
|
||||
exec_and_count(28, $db, 'CREATE FUNCTION f( ver_param VARCHAR(255)) RETURNS VARCHAR(255) DETERMINISTIC RETURN ver_param;', 0);
|
||||
// we got this far without problems. If there's an issue from now on, its a failure
|
||||
$ignore_exception = false;
|
||||
$stmt = $db->query('SELECT f(VERSION()) AS f_version');
|
||||
$tmp = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
if (count($tmp) > 1 || !isset($tmp[0]['f_version'])) {
|
||||
printf("[029] Data seems wrong, dumping\n");
|
||||
var_dump($tmp);
|
||||
} else {
|
||||
$f_version = $tmp[0]['f_version'];
|
||||
}
|
||||
$stmt = $db->query('SELECT VERSION() AS _version');
|
||||
$tmp = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
if (count($tmp) > 1 || !isset($tmp[0]['_version'])) {
|
||||
printf("[030] Data seems wrong, dumping\n");
|
||||
var_dump($tmp);
|
||||
} else {
|
||||
if ($f_version !== $tmp[0]['_version']) {
|
||||
printf("[031] Found different version strings, SF returned '%s'/%s, SELECT returned '%s'/%s\n",
|
||||
$f_version, gettype($f_version),
|
||||
$tmp[0]['_version'], gettype($tmp[0]['_version']));
|
||||
}
|
||||
}
|
||||
exec_and_count(32, $db, 'DROP FUNCTION IF EXISTS f', 0);
|
||||
|
||||
} catch (PDOException $e) {
|
||||
// ignore it, we might not have sufficient permissions
|
||||
if (!$ignore_exception)
|
||||
printf("[026] %s, [%s] %s\n",
|
||||
$e->getMessage(),
|
||||
$db->errorCode(), implode(' ', $db->errorInfo()));
|
||||
}
|
||||
}
|
||||
|
||||
// multi query
|
||||
try {
|
||||
|
||||
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1);
|
||||
$exp = 0;
|
||||
|
||||
$tmp = @$db->exec(sprintf('DROP TABLE IF EXISTS test; CREATE TABLE test(id INT) ENGINE=%s', PDO_MYSQL_TEST_ENGINE));
|
||||
if ($exp !== $tmp)
|
||||
printf("[034] Expecting %s/%s got %s/%s, [%s] %s\n",
|
||||
$exp, gettype($exp),
|
||||
$tmp, gettype($tmp),
|
||||
$db->errorCode(), var_export($db->errorInfo(), true));
|
||||
|
||||
// this is interesting: if we get sort of affected rows, what will happen now?
|
||||
$tmp = @$db->exec('INSERT INTO test(id) VALUES (1); INSERT INTO test(id) VALUES (2)');
|
||||
printf("[035] With emulated PS it works but makes no sense given that exec() returns sort of affected rows...\n");
|
||||
|
||||
|
||||
} catch (PDOException $e) {
|
||||
printf("[033] %s, [%s] %s\n",
|
||||
$e->getMessage(),
|
||||
$db->errorCode(), implode(' ', $db->errorInfo()));
|
||||
}
|
||||
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0);
|
||||
|
||||
print "done!";
|
||||
?><?php
|
||||
require dirname(__FILE__) . '/mysql_pdo_test.inc';
|
||||
$db = MySQLPDOTest::factory();
|
||||
@$db->exec('DROP TABLE IF EXISTS test');
|
||||
?>
|
||||
@@ -0,0 +1,4 @@
|
||||
HipHop Warning: %a
|
||||
[016] [42000] 42000 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'THIS IS NOT VALID SQL, I HOPE' at line %d
|
||||
[035] With emulated PS it works but makes no sense given that exec() returns sort of affected rows...
|
||||
done!
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
function exec_and_count($offset, &$db, $sql, $exp, $suppress_warning = false) {
|
||||
|
||||
try {
|
||||
|
||||
if ($suppress_warning)
|
||||
$ret = @$db->exec($sql);
|
||||
else
|
||||
$ret = $db->exec($sql);
|
||||
|
||||
if ($ret !== $exp) {
|
||||
printf("[%03d] Expecting '%s'/%s got '%s'/%s when running '%s', [%s] %s\n",
|
||||
$offset, $exp, gettype($exp), $ret, gettype($ret), $sql,
|
||||
$db->errorCode(), implode(' ', $db->errorInfo()));
|
||||
return false;
|
||||
}
|
||||
|
||||
} catch (PDOException $e) {
|
||||
printf("[%03d] '%s' has failed, [%s] %s\n",
|
||||
$offset, $sql, $db->errorCode(), implode(' ', $db->errorInfo()));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
|
||||
$db = MySQLPDOTest::factory();
|
||||
MySQLPDOTest::createTestTable($db, MySQLPDOTest::detect_transactional_mysql_engine($db));
|
||||
|
||||
/* affected rows related */
|
||||
try {
|
||||
|
||||
@$db->exec('DROP DATABASE IF EXISTS pdo_exec_ddl');
|
||||
@$db->exec('DROP DATABASE IF EXISTS pdo_exec_ddl2');
|
||||
if (1 === @$db->exec('CREATE DATABASE pdo_exec_ddl')) {
|
||||
// yippie - we can create databases etc.
|
||||
exec_and_count(3, $db, 'ALTER DATABASE pdo_exec_ddl CHARACTER SET latin1', 1);
|
||||
}
|
||||
|
||||
exec_and_count(4, $db, 'DROP TABLE IF EXISTS pdo_exec_ddl', 0);
|
||||
exec_and_count(5, $db, 'DROP TABLE IF EXISTS pdo_exec_ddl2', 0);
|
||||
if (0 === $db->exec('CREATE TABLE pdo_exec_ddl(id INT, col1 CHAR(2))')) {
|
||||
exec_and_count(5, $db, 'CREATE INDEX idx1 ON pdo_exec_ddl(id)', 0);
|
||||
exec_and_count(6, $db, 'DROP INDEX idx1 ON pdo_exec_ddl', 0);
|
||||
exec_and_count(7, $db, 'ALTER TABLE pdo_exec_ddl DROP id', 0);
|
||||
exec_and_count(8, $db, 'ALTER TABLE pdo_exec_ddl ADD id INT', 0);
|
||||
exec_and_count(9, $db, 'ALTER TABLE pdo_exec_ddl ALTER id SET DEFAULT 1', 0);
|
||||
exec_and_count(10, $db, 'RENAME TABLE pdo_exec_ddl TO pdo_exec_ddl2', 0);
|
||||
}
|
||||
|
||||
/*
|
||||
11.1.2. ALTER LOGFILE GROUP Syntax
|
||||
11.1.3. ALTER SERVER Syntax
|
||||
11.1.5. ALTER TABLESPACE Syntax
|
||||
11.1.8. CREATE LOGFILE GROUP Syntax
|
||||
11.1.9. CREATE SERVER Syntax
|
||||
11.1.11. CREATE TABLESPACE Syntax
|
||||
11.1.14. DROP LOGFILE GROUP Syntax
|
||||
11.1.15. DROP SERVER Syntax
|
||||
11.1.17. DROP TABLESPACE Syntax
|
||||
*/
|
||||
|
||||
} catch (PDOException $e) {
|
||||
printf("[001] %s, [%s] %s\n",
|
||||
$e->getMessage(),
|
||||
$db->errorCode(), implode(' ', $db->errorInfo()));
|
||||
}
|
||||
|
||||
print "done!";<?php
|
||||
require dirname(__FILE__) . '/mysql_pdo_test.inc';
|
||||
$db = MySQLPDOTest::factory();
|
||||
MySQLPDOTest::dropTestTable($db);
|
||||
// clean up
|
||||
@$db->exec('DROP TABLE IF EXISTS pdo_exec_ddl');
|
||||
@$db->exec('DROP TABLE IF EXISTS pdo_exec_ddl2');
|
||||
@$db->exec('DROP DATABASE IF EXISTS pdo_exec_ddl');
|
||||
@$db->exec('DROP DATABASE IF EXISTS pdo_exec_ddl2');
|
||||
?>
|
||||
@@ -0,0 +1 @@
|
||||
done!
|
||||
Alguns arquivos não foram exibidos porque demasiados arquivos foram alterados neste diff Mostrar Mais
Referência em uma Nova Issue
Bloquear um usuário