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

59 lines
1.6 KiB
Plaintext
Raw Normal View History

2017-05-03 23:04:17 +02:00
--TEST--
Test the bindColumn method using either by bind by column number or bind by column name
--SKIPIF--
<?php require "skipif_mid-refactor.inc"; ?>
2017-05-03 23:04:17 +02:00
--FILE--
<?php
require_once("MsCommon_mid-refactor.inc");
require_once("MsData_PDO_AllTypes.inc");
2017-05-03 23:04:17 +02:00
2017-11-04 01:01:09 +01:00
function bindColumnByName($db, $tbname)
2017-05-03 23:04:17 +02:00
{
$stmt = $db->prepare("SELECT IntCol, CharCol, DateTimeCol FROM $tbname");
2017-05-03 23:04:17 +02:00
$stmt->execute();
$stmt->bindColumn('IntCol', $intCol);
$stmt->bindColumn('CharCol', $charCol);
$stmt->bindColumn('DateTimeCol', $dateTimeCol);
while ($row = $stmt->fetch(PDO::FETCH_BOUND)) {
2017-05-03 23:04:17 +02:00
echo $intCol . " : " . $charCol . " : " . $dateTimeCol . "\n";
}
}
2017-11-04 01:01:09 +01:00
function bindColumnByNumber($db, $tbname)
2017-05-03 23:04:17 +02:00
{
$stmt = $db->prepare("SELECT IntCol, CharCol, DateTimeCol FROM $tbname");
2017-05-03 23:04:17 +02:00
$stmt->execute();
$stmt->bindColumn(1, $intCol);
$stmt->bindColumn(2, $charCol);
$stmt->bindColumn(3, $dateTimeCol);
while ($row = $stmt->fetch(PDO::FETCH_BOUND)) {
2017-05-03 23:04:17 +02:00
echo $intCol . " : " . $charCol . " : " . $dateTimeCol . "\n";
}
}
try {
2017-05-03 23:04:17 +02:00
$db = connect();
$tbname = "PDO_MainTypes";
createAndInsertTableMainTypes($db, $tbname);
2017-05-03 23:04:17 +02:00
echo "Bind Column by name :\n";
2017-11-04 01:01:09 +01:00
bindColumnByName($db, $tbname);
2017-05-03 23:04:17 +02:00
echo "Bind Column by number :\n";
2017-11-04 01:01:09 +01:00
bindColumnByNumber($db, $tbname);
dropTable($db, $tbname);
unset($db);
} catch (PDOException $e) {
2017-05-03 23:04:17 +02:00
var_dump($e);
}
?>
--EXPECT--
Bind Column by name :
1 : STRINGCOL1 : 2000-11-11 11:11:11.110
2 : STRINGCOL2 : 2000-11-11 11:11:11.223
Bind Column by number :
1 : STRINGCOL1 : 2000-11-11 11:11:11.110
2 : STRINGCOL2 : 2000-11-11 11:11:11.223