vendor/doctrine/dbal/src/Driver/PDO/Statement.php line 130

Open in your IDE?
  1. <?php
  2. namespace Doctrine\DBAL\Driver\PDO;
  3. use Doctrine\DBAL\Driver\Exception\UnknownParameterType;
  4. use Doctrine\DBAL\Driver\Result as ResultInterface;
  5. use Doctrine\DBAL\Driver\Statement as StatementInterface;
  6. use Doctrine\DBAL\ParameterType;
  7. use Doctrine\Deprecations\Deprecation;
  8. use PDOException;
  9. use PDOStatement;
  10. use function array_slice;
  11. use function func_get_args;
  12. use function func_num_args;
  13. final class Statement implements StatementInterface
  14. {
  15.     private PDOStatement $stmt;
  16.     /** @internal The statement can be only instantiated by its driver connection. */
  17.     public function __construct(PDOStatement $stmt)
  18.     {
  19.         $this->stmt $stmt;
  20.     }
  21.     /**
  22.      * {@inheritDoc}
  23.      *
  24.      * @throws UnknownParameterType
  25.      *
  26.      * @psalm-assert ParameterType::* $type
  27.      */
  28.     public function bindValue($param$value$type ParameterType::STRING)
  29.     {
  30.         if (func_num_args() < 3) {
  31.             Deprecation::trigger(
  32.                 'doctrine/dbal',
  33.                 'https://github.com/doctrine/dbal/pull/5558',
  34.                 'Not passing $type to Statement::bindValue() is deprecated.'
  35.                     ' Pass the type corresponding to the parameter being bound.',
  36.             );
  37.         }
  38.         $pdoType ParameterTypeMap::convertParamType($type);
  39.         try {
  40.             return $this->stmt->bindValue($param$value$pdoType);
  41.         } catch (PDOException $exception) {
  42.             throw Exception::new($exception);
  43.         }
  44.     }
  45.     /**
  46.      * {@inheritDoc}
  47.      *
  48.      * @deprecated Use {@see bindValue()} instead.
  49.      *
  50.      * @param mixed    $param
  51.      * @param mixed    $variable
  52.      * @param int      $type
  53.      * @param int|null $length
  54.      * @param mixed    $driverOptions The usage of the argument is deprecated.
  55.      *
  56.      * @throws UnknownParameterType
  57.      *
  58.      * @psalm-assert ParameterType::* $type
  59.      */
  60.     public function bindParam(
  61.         $param,
  62.         &$variable,
  63.         $type ParameterType::STRING,
  64.         $length null,
  65.         $driverOptions null
  66.     ): bool {
  67.         Deprecation::trigger(
  68.             'doctrine/dbal',
  69.             'https://github.com/doctrine/dbal/pull/5563',
  70.             '%s is deprecated. Use bindValue() instead.',
  71.             __METHOD__,
  72.         );
  73.         if (func_num_args() < 3) {
  74.             Deprecation::trigger(
  75.                 'doctrine/dbal',
  76.                 'https://github.com/doctrine/dbal/pull/5558',
  77.                 'Not passing $type to Statement::bindParam() is deprecated.'
  78.                     ' Pass the type corresponding to the parameter being bound.',
  79.             );
  80.         }
  81.         if (func_num_args() > 4) {
  82.             Deprecation::triggerIfCalledFromOutside(
  83.                 'doctrine/dbal',
  84.                 'https://github.com/doctrine/dbal/issues/4533',
  85.                 'The $driverOptions argument of Statement::bindParam() is deprecated.',
  86.             );
  87.         }
  88.         $pdoType ParameterTypeMap::convertParamType($type);
  89.         try {
  90.             return $this->stmt->bindParam(
  91.                 $param,
  92.                 $variable,
  93.                 $pdoType,
  94.                 $length ?? 0,
  95.                 ...array_slice(func_get_args(), 4),
  96.             );
  97.         } catch (PDOException $exception) {
  98.             throw Exception::new($exception);
  99.         }
  100.     }
  101.     /**
  102.      * {@inheritDoc}
  103.      */
  104.     public function execute($params null): ResultInterface
  105.     {
  106.         if ($params !== null) {
  107.             Deprecation::trigger(
  108.                 'doctrine/dbal',
  109.                 'https://github.com/doctrine/dbal/pull/5556',
  110.                 'Passing $params to Statement::execute() is deprecated. Bind parameters using'
  111.                     ' Statement::bindParam() or Statement::bindValue() instead.',
  112.             );
  113.         }
  114.         try {
  115.             $this->stmt->execute($params);
  116.         } catch (PDOException $exception) {
  117.             throw Exception::new($exception);
  118.         }
  119.         return new Result($this->stmt);
  120.     }
  121. }