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

90 lines
1.8 KiB
Plaintext
Raw Normal View History

2017-02-04 01:07:19 +01:00
--TEST--
Bind values with PDO::PARAM_BOOL, enable/disable fetch numeric type attribute
--SKIPIF--
<?php require('skipif_mid-refactor.inc'); ?>
2017-02-04 01:07:19 +01:00
--FILE--
<?php
require_once( "MsCommon_mid-refactor.inc" );
2017-02-04 01:07:19 +01:00
try {
// Sample data
$sample = array([true, false],[-12, 0x2A],[0.00, NULL]);
$tableName = "pdo_test_table";
2017-02-04 01:07:19 +01:00
// Connect
$conn = connect();
2017-02-04 01:07:19 +01:00
// Run test
Test();
2017-02-04 01:07:19 +01:00
// Set PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE = false (default)
$conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, FALSE);
Test();
2017-02-04 01:07:19 +01:00
// Set PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE = true
$conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, TRUE);
Test();
2017-02-04 01:07:19 +01:00
// Close connection
unset($stmt);
unset($conn);
2017-02-04 01:07:19 +01:00
print "Done";
} catch (PDOException $e) {
var_dump($e->errorInfo);
}
2017-02-04 01:07:19 +01:00
// Generic test starts here
function Test()
{
2017-05-02 21:00:53 +02:00
global $conn, $tableName, $sample;
2017-02-04 01:07:19 +01:00
2017-05-02 21:00:53 +02:00
// Drop table if exists
createTable($conn, $tableName, array("c1" => "int", "c2" => "bit"));
2017-05-02 21:00:53 +02:00
// Insert data using bind values
$sql = "INSERT INTO $tableName VALUES (:v1, :v2)";
$stmt = $conn->prepare($sql);
foreach ($sample as $s) {
$stmt->bindValue(':v1', $s[0], PDO::PARAM_BOOL);
$stmt->bindValue(':v2', $s[1], PDO::PARAM_BOOL);
$stmt->execute();
}
2017-02-04 01:07:19 +01:00
2017-05-02 21:00:53 +02:00
// Get data
$sql = "SELECT * FROM $tableName";
$stmt = $conn->query($sql);
$row = $stmt->fetchAll(PDO::FETCH_NUM);
2017-02-04 01:07:19 +01:00
2017-05-02 21:00:53 +02:00
// Print out
for ($i=0; $i<$stmt->rowCount(); $i++) {
var_dump($row[$i][0]); var_dump($row[$i][1]);
}
// clean up
dropTable( $conn, $tableName );
unset( $stmt );
2017-02-04 01:07:19 +01:00
}
?>
--EXPECT--
string(1) "1"
string(1) "0"
string(1) "1"
string(1) "1"
string(1) "0"
NULL
string(1) "1"
string(1) "0"
string(1) "1"
string(1) "1"
string(1) "0"
NULL
int(1)
int(0)
int(1)
int(1)
int(0)
NULL
Done