PdoValue.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * @link https://www.yiiframework.com/
  4. * @copyright Copyright (c) 2008 Yii Software LLC
  5. * @license https://www.yiiframework.com/license/
  6. */
  7. namespace yii\db;
  8. /**
  9. * Class PdoValue represents a $value that should be bound to PDO with exact $type.
  10. *
  11. * For example, it will be useful when you need to bind binary data to BLOB column in DBMS:
  12. *
  13. * ```php
  14. * [':name' => 'John', ':profile' => new PdoValue($profile, \PDO::PARAM_LOB)]`.
  15. * ```
  16. *
  17. * To see possible types, check [PDO::PARAM_* constants](https://www.php.net/manual/en/pdo.constants.php).
  18. *
  19. * @see https://www.php.net/manual/en/pdostatement.bindparam.php
  20. * @author Dmytro Naumenko <d.naumenko.a@gmail.com>
  21. * @since 2.0.14
  22. * @phpcs:disable Squiz.NamingConventions.ValidVariableName.PrivateNoUnderscore
  23. */
  24. final class PdoValue implements ExpressionInterface
  25. {
  26. /**
  27. * @var mixed
  28. */
  29. private $value;
  30. /**
  31. * @var int One of PDO_PARAM_* constants
  32. * @see https://www.php.net/manual/en/pdo.constants.php
  33. */
  34. private $type;
  35. /**
  36. * PdoValue constructor.
  37. *
  38. * @param $value
  39. * @param $type
  40. */
  41. public function __construct($value, $type)
  42. {
  43. $this->value = $value;
  44. $this->type = $type;
  45. }
  46. /**
  47. * @return mixed
  48. */
  49. public function getValue()
  50. {
  51. return $this->value;
  52. }
  53. /**
  54. * @return int
  55. */
  56. public function getType()
  57. {
  58. return $this->type;
  59. }
  60. }