PdoValue.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * @link http://www.yiiframework.com/
  4. * @copyright Copyright (c) 2008 Yii Software LLC
  5. * @license http://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://secure.php.net/manual/en/pdo.constants.php).
  18. *
  19. * @see https://secure.php.net/manual/en/pdostatement.bindparam.php
  20. * @author Dmytro Naumenko <d.naumenko.a@gmail.com>
  21. * @since 2.0.14
  22. */
  23. final class PdoValue implements ExpressionInterface
  24. {
  25. /**
  26. * @var mixed
  27. */
  28. private $value;
  29. /**
  30. * @var int One of PDO_PARAM_* constants
  31. * @see https://secure.php.net/manual/en/pdo.constants.php
  32. */
  33. private $type;
  34. /**
  35. * PdoValue constructor.
  36. *
  37. * @param $value
  38. * @param $type
  39. */
  40. public function __construct($value, $type)
  41. {
  42. $this->value = $value;
  43. $this->type = $type;
  44. }
  45. /**
  46. * @return mixed
  47. */
  48. public function getValue()
  49. {
  50. return $this->value;
  51. }
  52. /**
  53. * @return int
  54. */
  55. public function getType()
  56. {
  57. return $this->type;
  58. }
  59. }