Skip to content

Instantly share code, notes, and snippets.

@mpdude
Created September 8, 2018 21:43
Show Gist options
  • Save mpdude/1ad1c03556d9fd4191396159b7929124 to your computer and use it in GitHub Desktop.
Save mpdude/1ad1c03556d9fd4191396159b7929124 to your computer and use it in GitHub Desktop.
diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php
index 571f16232..bf823e56d 100644
--- a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php
+++ b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php
@@ -87,10 +87,10 @@ class MysqliStatement implements \IteratorAggregate, Statement
protected $_values = [];
/**
- * Contains values from bindValue() that need to be sent
+ * Contains streams passed to bindValue() that need to be sent
* using send_long_data *after* bind_param has been called.
*
- * @var mixed[]
+ * @var resource[]
*/
protected $_longData = [];
@@ -154,8 +154,12 @@ class MysqliStatement implements \IteratorAggregate, Statement
public function bindValue($param, $value, $type = ParameterType::STRING)
{
if ($type === ParameterType::LARGE_OBJECT) {
- $this->_longData[$param - 1] = $value;
- $value = null;
+ if (is_resource($value) && get_resource_type($value) === 'stream') {
+ $this->_longData[$param - 1] = $value;
+ $value = null;
+ } else {
+ $type = ParameterType::STRING;
+ }
}
if (null === $type) {
@@ -252,15 +256,9 @@ class MysqliStatement implements \IteratorAggregate, Statement
private function _sendLongData()
{
foreach ($this->_longData as $paramNr => $resource) {
- if (is_resource($resource) && get_resource_type($resource) === 'stream') {
- while (! feof($resource)) {
- $longData = fread($resource, 8192);
- if (! $this->_stmt->send_long_data($paramNr, $longData)) {
- throw new MysqliException($this->_stmt->error, $this->_stmt->sqlstate, $this->_stmt->errno);
- }
- }
- } else {
- if (! $this->_stmt->send_long_data($paramNr, $resource)) {
+ while (! feof($resource)) {
+ $longData = fread($resource, 8192);
+ if (! $this->_stmt->send_long_data($paramNr, $longData)) {
throw new MysqliException($this->_stmt->error, $this->_stmt->sqlstate, $this->_stmt->errno);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment