Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #35 #286

Merged
merged 3 commits into from
Feb 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions source/pdo_sqlsrv/pdo_stmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,10 @@ int pdo_sqlsrv_stmt_get_col_data(pdo_stmt_t *stmt, int colno,

pdo_bound_param_data* bind_data = NULL;
bind_data = reinterpret_cast<pdo_bound_param_data*>(zend_hash_index_find_ptr(stmt->bound_columns, colno));
if (bind_data == NULL) {
// can't find by index then try searching by name
bind_data = reinterpret_cast<pdo_bound_param_data*>(zend_hash_find_ptr(stmt->bound_columns, stmt->columns[colno].name));
}

if( bind_data != NULL && !Z_ISUNDEF(bind_data->driver_params) ) {

Expand Down
50 changes: 50 additions & 0 deletions test/pdo_sqlsrv/pdo_035_binary_encoding_error_bound_by_name.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
--TEST--
GitHub Issue #35 binary encoding error when binding by name
--SKIPIF--
--FILE--
<?php
function test()
{
require_once("autonomous_setup.php");

// Connect
$dbName = "tempdb";
$conn = new PDO( "sqlsrv:server=$serverName ; database=$dbName", $username, $password);

// Create a temp table
$number = rand(0,1000);
$tableName = "testTableIssue35" . "_" . $number;
$sql = "CREATE TABLE $tableName (Value varbinary(max))";
$stmt = $conn->query($sql);

// Insert data using bind parameters
$sql = "INSERT INTO $tableName VALUES (?)";
$stmt = $conn->prepare($sql);
$message = "This is to test github issue 35.";
$value = base64_encode($message);

$stmt->setAttribute(constant('PDO::SQLSRV_ATTR_ENCODING'), PDO::SQLSRV_ENCODING_BINARY);
$stmt->bindParam(1, $value, PDO::PARAM_LOB);
$result = $stmt->execute();

// fetch it back
$stmt = $conn->prepare("SELECT Value FROM $tableName");
$stmt->bindColumn('Value', $val1, PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY);
$stmt->execute();
$stmt->fetch(PDO::FETCH_BOUND);
var_dump($val1 === $value);

$stmt = $conn->query("DROP TABLE $tableName");

// Close connection
$stmt = null;
$conn = null;
}

test();
print "Done";
?>
--EXPECT--
bool(true)
Done