public static function Utils::bindValues in Drupal driver for SQL Server and SQL Azure 4.1.x
Same name and namespace in other branches
- 4.2.x src/Driver/Database/sqlsrv/Utils.php \Drupal\sqlsrv\Driver\Database\sqlsrv\Utils::bindValues()
- 3.1.x src/Driver/Database/sqlsrv/Utils.php \Drupal\sqlsrv\Driver\Database\sqlsrv\Utils::bindValues()
- 4.0.x src/Driver/Database/sqlsrv/Utils.php \Drupal\sqlsrv\Driver\Database\sqlsrv\Utils::bindValues()
Binds a set of values to a PDO Statement.
Takes care of properly managing binary data.
Parameters
StatementWrapper $stmt: PDOStatement to bind the values to.
array $values: Values to bind. It's an array where the keys are column names and the values what is going to be inserted.
array $blobs: When sending binary data to the PDO driver, we need to keep track of the original references to data.
mixed $placeholder_prefix: Prefix to use for generating the query placeholders.
array $columnInformation: Column information.
mixed $max_placeholder: Placeholder count, if NULL will start with 0.
mixed $blob_suffix: Suffix for the blob key.
3 calls to Utils::bindValues()
- Insert::execute in src/
Driver/ Database/ sqlsrv/ Insert.php - Runs the query against the database.
- Update::execute in src/
Driver/ Database/ sqlsrv/ Update.php - Executes the UPDATE query.
- Upsert::execute in src/
Driver/ Database/ sqlsrv/ Upsert.php - Executes the UPSERT operation.
File
- src/
Driver/ Database/ sqlsrv/ Utils.php, line 49
Class
- Utils
- Utility function for the SQL Server driver.
Namespace
Drupal\sqlsrv\Driver\Database\sqlsrvCode
public static function bindValues(StatementWrapper $stmt, array &$values, array &$blobs, $placeholder_prefix, array $columnInformation, &$max_placeholder = NULL, $blob_suffix = NULL) {
if (empty($max_placeholder)) {
$max_placeholder = 0;
}
foreach ($values as $field_name => &$field_value) {
$placeholder = $placeholder_prefix . $max_placeholder++;
$blob_key = $placeholder . $blob_suffix;
if (isset($columnInformation['blobs'][$field_name])) {
$blobs[$blob_key] = fopen('php://memory', 'a');
fwrite($blobs[$blob_key], $field_value);
rewind($blobs[$blob_key]);
$stmt
->getClientStatement()
->bindParam($placeholder, $blobs[$blob_key], \PDO::PARAM_LOB, 0, \PDO::SQLSRV_ENCODING_BINARY);
}
else {
// Even though not a blob, make sure we retain a copy of these values.
$blobs[$blob_key] = $field_value;
$stmt
->getClientStatement()
->bindParam($placeholder, $blobs[$blob_key], \PDO::PARAM_STR);
}
}
}