php-sqlsrv/test/functional/pdo_sqlsrv/pdo_prepare_attribute.phpt

73 lines
1.6 KiB
Plaintext
Raw Normal View History

2017-05-03 22:09:02 +02:00
--TEST--
Test PDO::prepare() with PDO::ATTR_EMULATE_PREPARES.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require_once('skipif_mid-refactor.inc'); ?>
<?php require('skipif_azure_dw.inc'); ?>
2017-05-03 22:09:02 +02:00
--FILE--
<?php
require_once("MsCommon_mid-refactor.inc");
2017-05-03 22:09:02 +02:00
$db = connect();
// retrieve correct results
$s = $db->prepare("SELECT '' + TITLE FROM cd_info GROUP BY '' + TITLE");
2017-05-03 22:09:02 +02:00
$s->execute();
$titles = array();
while ($r = $s->fetch()) {
$titles[] = $r[0];
2017-05-03 22:09:02 +02:00
}
$exception_thrown = false;
try {
$s = $db->prepare('SELECT :prefix + TITLE FROM cd_info GROUP BY :prefix + TITLE');
$s->bindValue(':prefix', "");
$s->execute();
while ($r = $s->fetch()) {
print_r($r);
}
} catch (PDOException $e) {
2017-05-03 22:09:02 +02:00
$exception_thrown = true;
}
if (!$exception_thrown) {
die("Exception not thrown\nTest failed\n");
2017-05-03 22:09:02 +02:00
}
// Column encryption is not supported by emulate prepared statement
$option[PDO::ATTR_EMULATE_PREPARES] = true;
2017-12-06 01:32:18 +01:00
if (isAEConnected()) {
$option[PDO::ATTR_EMULATE_PREPARES] = false;
}
2017-05-03 22:09:02 +02:00
if (!isAEConnected()) {
$s = $db->prepare("SELECT :prefix + TITLE FROM cd_info GROUP BY :prefix + TITLE", $option);
$s->bindValue(':prefix', "");
} else {
// binding parameters in the select list is not supported with Column Encryption
$s = $db->prepare("SELECT TITLE FROM cd_info GROUP BY TITLE", $option);
}
2017-05-03 22:09:02 +02:00
$s->execute();
$param_titles = array();
while ($r = $s->fetch()) {
$param_titles[] = $r[0];
2017-05-03 22:09:02 +02:00
}
if ($titles === $param_titles) {
2017-05-03 22:09:02 +02:00
echo "Test succeeded\n";
} else {
2017-05-03 22:09:02 +02:00
echo "Test failed\n";
print_r($titles);
print_r($param_titles);
2017-05-03 22:09:02 +02:00
}
?>
--EXPECT--
Test succeeded