CDbExpression.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * CDbExpression class file.
  4. *
  5. * @author Qiang Xue <qiang.xue@gmail.com>
  6. * @link http://www.yiiframework.com/
  7. * @copyright 2008-2013 Yii Software LLC
  8. * @license http://www.yiiframework.com/license/
  9. */
  10. /**
  11. * CDbExpression represents a DB expression that does not need escaping.
  12. * CDbExpression is mainly used in {@link CActiveRecord} as attribute values.
  13. * When inserting or updating a {@link CActiveRecord}, attribute values of
  14. * type CDbExpression will be directly put into the corresponding SQL statement
  15. * without escaping. A typical usage is that an attribute is set with 'NOW()'
  16. * expression so that saving the record would fill the corresponding column
  17. * with the current DB server timestamp.
  18. *
  19. * Starting from version 1.1.1, one can also specify parameters to be bound
  20. * for the expression. For example, if the expression is 'LOWER(:value)', then
  21. * one can set {@link params} to be <code>array(':value'=>$value)</code>.
  22. *
  23. * @author Qiang Xue <qiang.xue@gmail.com>
  24. * @package system.db.schema
  25. */
  26. class CDbExpression extends CComponent
  27. {
  28. /**
  29. * @var string the DB expression
  30. */
  31. public $expression;
  32. /**
  33. * @var array list of parameters that should be bound for this expression.
  34. * The keys are placeholders appearing in {@link expression}, while the values
  35. * are the corresponding parameter values.
  36. * @since 1.1.1
  37. */
  38. public $params=array();
  39. /**
  40. * Constructor.
  41. * @param string $expression the DB expression
  42. * @param array $params parameters
  43. */
  44. public function __construct($expression,$params=array())
  45. {
  46. $this->expression=$expression;
  47. $this->params=$params;
  48. }
  49. /**
  50. * String magic method
  51. * @return string the DB expression
  52. */
  53. public function __toString()
  54. {
  55. return $this->expression;
  56. }
  57. }