2017-05-03 23:04:17 +02:00
|
|
|
--TEST--
|
|
|
|
PDO Bind Param Truncation Test
|
|
|
|
--DESCRIPTION--
|
|
|
|
Verification for "PDOStatement::bindParam()".
|
|
|
|
--ENV--
|
|
|
|
PHPT_EXEC=true
|
|
|
|
--SKIPIF--
|
2017-11-30 23:37:25 +01:00
|
|
|
<?php require_once('skipif_mid-refactor.inc'); ?>
|
2017-05-03 23:04:17 +02:00
|
|
|
--FILE--
|
|
|
|
<?php
|
2017-11-30 23:37:25 +01:00
|
|
|
require_once("MsCommon_mid-refactor.inc");
|
|
|
|
|
|
|
|
try {
|
|
|
|
$conn1 = connect();
|
|
|
|
|
|
|
|
// Prepare test table
|
|
|
|
$tableName = "pdo_test_table";
|
2017-12-19 01:00:02 +01:00
|
|
|
createTable($conn1, $tableName, array(new ColumnMeta("int", "id", "IDENTITY NOT NULL"), "class" => "int", "value" => "char(32)"));
|
2017-11-30 23:37:25 +01:00
|
|
|
$conn1->exec("CREATE CLUSTERED INDEX [idx_test_int] ON $tableName (id)");
|
2017-12-19 01:00:02 +01:00
|
|
|
$tsql = "INSERT INTO [$tableName] (class, value) VALUES(:class, :value)";
|
2017-11-30 23:37:25 +01:00
|
|
|
|
|
|
|
$id = 0;
|
|
|
|
$class = 0;
|
|
|
|
$value = '';
|
|
|
|
|
|
|
|
// Prepare insert query$
|
2017-12-14 17:12:42 +01:00
|
|
|
$stmt1 = $conn1->prepare($tsql);
|
2017-12-19 01:00:02 +01:00
|
|
|
bindParam(1, $stmt1, ':class', $class);
|
|
|
|
bindParam(2, $stmt1, ':value', $value);
|
2017-11-30 23:37:25 +01:00
|
|
|
|
|
|
|
// Insert test rows
|
|
|
|
$class = 4;
|
|
|
|
$value = '2011';
|
|
|
|
execStmt(1, $stmt1);
|
|
|
|
|
|
|
|
$class = 5;
|
|
|
|
$value = 'Sat, 20 Mar 10 21:29:13 -0600';
|
|
|
|
execStmt(2, $stmt1);
|
|
|
|
|
|
|
|
$class = 6;
|
|
|
|
$value = 'Fri, 07 May 10 11:35:32 -0600';
|
|
|
|
execStmt(3, $stmt1);
|
|
|
|
|
|
|
|
unset($stmt1);
|
|
|
|
|
|
|
|
// Check data
|
|
|
|
$id = 0;
|
|
|
|
$value = '';
|
2017-12-19 01:00:02 +01:00
|
|
|
$tsql = "SELECT id, value FROM [$tableName] ORDER BY id";
|
2017-12-14 17:12:42 +01:00
|
|
|
$stmt2 = $conn1->query($tsql);
|
2017-11-30 23:37:25 +01:00
|
|
|
bindColumn(1, $stmt2, $id, $value);
|
|
|
|
while ($stmt2->fetch(PDO::FETCH_BOUND)) {
|
|
|
|
printf(
|
|
|
|
"id = %s (%s) / value = %s (%s)\n",
|
|
|
|
var_export($id, true),
|
|
|
|
gettype($id),
|
|
|
|
var_export($value, true),
|
|
|
|
gettype($value)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
unset($stmt2);
|
|
|
|
|
|
|
|
// Cleanup
|
|
|
|
dropTable($conn1, $tableName);
|
|
|
|
unset($stmt1);
|
|
|
|
unset($conn1);
|
|
|
|
} catch (Exception $e) {
|
|
|
|
echo $e->getMessage();
|
2017-05-03 23:04:17 +02:00
|
|
|
}
|
|
|
|
|
2017-11-30 23:37:25 +01:00
|
|
|
function bindParam($offset, $stmt, $param, &$value)
|
2017-05-03 23:04:17 +02:00
|
|
|
{
|
2017-11-30 23:37:25 +01:00
|
|
|
if (!$stmt->bindParam($param, $value)) {
|
2017-12-14 17:12:42 +01:00
|
|
|
logInfo($offset, "Cannot bind parameter $param");
|
2017-11-30 23:37:25 +01:00
|
|
|
}
|
2017-05-03 23:04:17 +02:00
|
|
|
}
|
|
|
|
|
2017-11-30 23:37:25 +01:00
|
|
|
function bindColumn($offset, $stmt, &$param1, &$param2)
|
2017-05-03 23:04:17 +02:00
|
|
|
{
|
2017-11-30 23:37:25 +01:00
|
|
|
if (!$stmt->bindColumn(1, $param1, PDO::PARAM_INT)) {
|
2017-12-14 17:12:42 +01:00
|
|
|
logInfo($offset, "Cannot bind integer column");
|
2017-11-30 23:37:25 +01:00
|
|
|
}
|
|
|
|
if (!$stmt->bindColumn(2, $param2, PDO::PARAM_STR)) {
|
2017-12-14 17:12:42 +01:00
|
|
|
logInfo($offset, "Cannot bind string column");
|
2017-11-30 23:37:25 +01:00
|
|
|
}
|
2017-05-03 23:04:17 +02:00
|
|
|
}
|
|
|
|
|
2017-11-30 23:37:25 +01:00
|
|
|
function execStmt($offset, $stmt)
|
2017-05-03 23:04:17 +02:00
|
|
|
{
|
2017-11-30 23:37:25 +01:00
|
|
|
if (!$stmt->execute()) {
|
2017-12-14 17:12:42 +01:00
|
|
|
logInfo($offset, "Cannot execute statement");
|
2017-11-30 23:37:25 +01:00
|
|
|
var_dump($stmt->errorInfo());
|
|
|
|
}
|
2017-05-03 23:04:17 +02:00
|
|
|
}
|
|
|
|
|
2017-12-14 17:12:42 +01:00
|
|
|
function logInfo($offset, $msg)
|
2017-05-03 23:04:17 +02:00
|
|
|
{
|
2017-11-30 23:37:25 +01:00
|
|
|
printf("[%03d] %s\n", $offset, $msg);
|
2017-05-03 23:04:17 +02:00
|
|
|
}
|
|
|
|
?>
|
|
|
|
--EXPECT--
|
|
|
|
id = 1 (integer) / value = '2011 ' (string)
|
|
|
|
id = 2 (integer) / value = 'Sat, 20 Mar 10 21:29:13 -0600 ' (string)
|
|
|
|
id = 3 (integer) / value = 'Fri, 07 May 10 11:35:32 -0600 ' (string)
|