Skip to content

Commit

Permalink
[9.x] Add resource binding (#41233)
Browse files Browse the repository at this point in the history
* Add support for binding resources (#41180)

* Remove duplicate code (#41180)

Binding of resource values is now handled in `Connection`.

* formatting

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
aedart and taylorotwell authored Feb 24, 2022
1 parent 3f2162a commit 7c2edfc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 28 deletions.
6 changes: 5 additions & 1 deletion src/Illuminate/Database/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,11 @@ public function bindValues($statement, $bindings)
$statement->bindValue(
is_string($key) ? $key : $key + 1,
$value,
is_int($value) ? PDO::PARAM_INT : PDO::PARAM_STR
match (true) {
is_int($value) => PDO::PARAM_INT,
is_resource($value) => PDO::PARAM_LOB,
default => PDO::PARAM_STR
},
);
}
}
Expand Down
27 changes: 0 additions & 27 deletions src/Illuminate/Database/PostgresConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,9 @@
use Illuminate\Database\Schema\PostgresBuilder;
use Illuminate\Database\Schema\PostgresSchemaState;
use Illuminate\Filesystem\Filesystem;
use PDO;

class PostgresConnection extends Connection
{
/**
* Bind values to their parameters in the given statement.
*
* @param \PDOStatement $statement
* @param array $bindings
* @return void
*/
public function bindValues($statement, $bindings)
{
foreach ($bindings as $key => $value) {
if (is_int($value)) {
$pdoParam = PDO::PARAM_INT;
} elseif (is_resource($value)) {
$pdoParam = PDO::PARAM_LOB;
} else {
$pdoParam = PDO::PARAM_STR;
}

$statement->bindValue(
is_string($key) ? $key : $key + 1,
$value,
$pdoParam
);
}
}

/**
* Get the default query grammar instance.
*
Expand Down

0 comments on commit 7c2edfc

Please sign in to comment.