1
Vote

Binary data not returned when column data or column bound by name

description

Hi,

When using the PDO php driver (v3) with the adventureworks sample db and either you add the following code to the sample (pdo_photo.php):

1)

$stmt->execute(array(&$_GET['productId']));

/ NEW CODE /

$data = array();
$count = $stmt->columnCount();
for ( $i = 0; $i < $count; $i++ )
{
$field_data_array = $stmt->getColumnMeta($i);
$data[$field_data->Name] = $field_data_array;
}

/ END NEW CODE /

$stmt->bindColumn(1, $image, PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY);


2)

$stmt->execute(array(&$_GET['productId']));

/ CHANGE column index to name, strange column indexes are 1 based /


$stmt->bindColumn(1, "LargePhoto", PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY);


Then the binary data is mangled and the photo is not displayed.

Yours,

Charles Durrant
Thomson Reuters

comments

charliedurrant wrote Nov 19, 2013 at 2:48 PM

Apologies, example 2) should be

$stmt->bindColumn("LargePhoto", $image, PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY);