diff --git a/source/pdo_sqlsrv/pdo_stmt.cpp b/source/pdo_sqlsrv/pdo_stmt.cpp index d8b086a72..6adfbd0c2 100644 --- a/source/pdo_sqlsrv/pdo_stmt.cpp +++ b/source/pdo_sqlsrv/pdo_stmt.cpp @@ -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(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(zend_hash_find_ptr(stmt->bound_columns, stmt->columns[colno].name)); + } if( bind_data != NULL && !Z_ISUNDEF(bind_data->driver_params) ) { diff --git a/test/pdo_sqlsrv/pdo_035_binary_encoding_error_bound_by_name.phpt b/test/pdo_sqlsrv/pdo_035_binary_encoding_error_bound_by_name.phpt new file mode 100644 index 000000000..35c695f55 --- /dev/null +++ b/test/pdo_sqlsrv/pdo_035_binary_encoding_error_bound_by_name.phpt @@ -0,0 +1,50 @@ +--TEST-- +GitHub Issue #35 binary encoding error when binding by name +--SKIPIF-- +--FILE-- +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 +