Skip to content
Open
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
24 changes: 24 additions & 0 deletions Tests/DatabaseQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,30 @@ public function testBind($key, $value, $dataType, $expected)
);
}

/**
* @testdox The bind method records a bound parameter for the query
*
* @param array|string|integer $key The key that will be used in your SQL query to reference the value. Usually of
* the form ':key', but can also be an integer.
* @param mixed $value The value that will be bound. It can be an array, in this case it has to be
* same length of $key; The value is passed by reference to support output
* parameters such as those possible with stored procedures.
* @param array|string $dataType Constant corresponding to a SQL datatype. It can be an array, in this case it
* has to be same length of $key
* @param array $expected The expected structure of `$bounded`
*/
public function testBindValue()
{
$this->assertSame($this->query, $this->query->bindValue(':bindValue', 'JustValueNoReference', ParameterType::STRING), 'The query builder supports method chaining');

$this->assertEquals(
[
':bindValue' => (object) ['value' => 'JustValueNoReference', 'dataType' => 'string', 'length' => 0, 'driverOptions' => []],
],
$this->query->bounded
);
}

/**
* @testdox The bind method does not record bound parameters when the keys and values are an unbalanced number of items
*/
Expand Down
24 changes: 24 additions & 0 deletions src/DatabaseQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -1939,6 +1939,30 @@ public function bind($key, &$value, $dataType = ParameterType::STRING, $length =
return $this;
}

/**
* Method to add a variable to an internal array that will be bound to a prepared SQL statement before query execution.
*
* Proxy method to self::bind() without the need to provide a referenceable input for value
*
* @param array|string|integer $key The key that will be used in your SQL query to reference the value. Usually of
* the form ':key', but can also be an integer.
* @param mixed $value The value that will be bound. It can be an array, in this case it has to be
* same length of $key
* @param array|string $dataType Constant corresponding to a SQL datatype. It can be an array, in this case it
* has to be same length of $key
* @param integer $length The length of the variable. Usually required for OUTPUT parameters.
* @param array $driverOptions Optional driver options to be used.
*
* @return $this
*
* @since __DEPLOY_VERSION__
* @throws \InvalidArgumentException
*/
public function bindValue($key, $value, $dataType = ParameterType::STRING, $length = 0, $driverOptions = [])
{
return $this->bind($key, $value, $dataType, $length, $driverOptions);
}

/**
* Method to unbind a bound variable.
*
Expand Down