vendor/doctrine/dbal/src/Logging/Statement.php line 98

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Doctrine\DBAL\Logging;
  4. use Doctrine\DBAL\Driver\Middleware\AbstractStatementMiddleware;
  5. use Doctrine\DBAL\Driver\Result as ResultInterface;
  6. use Doctrine\DBAL\Driver\Statement as StatementInterface;
  7. use Doctrine\DBAL\ParameterType;
  8. use Doctrine\Deprecations\Deprecation;
  9. use Psr\Log\LoggerInterface;
  10. use function array_slice;
  11. use function func_get_args;
  12. use function func_num_args;
  13. final class Statement extends AbstractStatementMiddleware
  14. {
  15. private LoggerInterface $logger;
  16. private string $sql;
  17. /** @var array<int,mixed>|array<string,mixed> */
  18. private array $params = [];
  19. /** @var array<int,int>|array<string,int> */
  20. private array $types = [];
  21. /** @internal This statement can be only instantiated by its connection. */
  22. public function __construct(StatementInterface $statement, LoggerInterface $logger, string $sql)
  23. {
  24. parent::__construct($statement);
  25. $this->logger = $logger;
  26. $this->sql = $sql;
  27. }
  28. /**
  29. * {@inheritDoc}
  30. *
  31. * @deprecated Use {@see bindValue()} instead.
  32. */
  33. public function bindParam($param, &$variable, $type = ParameterType::STRING, $length = null)
  34. {
  35. Deprecation::trigger(
  36. 'doctrine/dbal',
  37. 'https://github.com/doctrine/dbal/pull/5563',
  38. '%s is deprecated. Use bindValue() instead.',
  39. __METHOD__,
  40. );
  41. if (func_num_args() < 3) {
  42. Deprecation::trigger(
  43. 'doctrine/dbal',
  44. 'https://github.com/doctrine/dbal/pull/5558',
  45. 'Not passing $type to Statement::bindParam() is deprecated.'
  46. . ' Pass the type corresponding to the parameter being bound.',
  47. );
  48. }
  49. $this->params[$param] = &$variable;
  50. $this->types[$param] = $type;
  51. return parent::bindParam($param, $variable, $type, ...array_slice(func_get_args(), 3));
  52. }
  53. /**
  54. * {@inheritDoc}
  55. */
  56. public function bindValue($param, $value, $type = ParameterType::STRING)
  57. {
  58. if (func_num_args() < 3) {
  59. Deprecation::trigger(
  60. 'doctrine/dbal',
  61. 'https://github.com/doctrine/dbal/pull/5558',
  62. 'Not passing $type to Statement::bindValue() is deprecated.'
  63. . ' Pass the type corresponding to the parameter being bound.',
  64. );
  65. }
  66. $this->params[$param] = $value;
  67. $this->types[$param] = $type;
  68. return parent::bindValue($param, $value, $type);
  69. }
  70. /**
  71. * {@inheritDoc}
  72. */
  73. public function execute($params = null): ResultInterface
  74. {
  75. $this->logger->debug('Executing statement: {sql} (parameters: {params}, types: {types})', [
  76. 'sql' => $this->sql,
  77. 'params' => $params ?? $this->params,
  78. 'types' => $this->types,
  79. ]);
  80. return parent::execute($params);
  81. }
  82. }