Expr.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Db
  17. * @subpackage Expr
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * Class for SQL SELECT fragments.
  24. *
  25. * This class simply holds a string, so that fragments of SQL statements can be
  26. * distinguished from identifiers and values that should be implicitly quoted
  27. * when interpolated into SQL statements.
  28. *
  29. * For example, when specifying a primary key value when inserting into a new
  30. * row, some RDBMS brands may require you to use an expression to generate the
  31. * new value of a sequence. If this expression is treated as an identifier,
  32. * it will be quoted and the expression will not be evaluated. Another example
  33. * is that you can use Zend_Db_Expr in the Zend_Db_Select::order() method to
  34. * order by an expression instead of simply a column name.
  35. *
  36. * The way this works is that in each context in which a column name can be
  37. * specified to methods of Zend_Db classes, if the value is an instance of
  38. * Zend_Db_Expr instead of a plain string, then the expression is not quoted.
  39. * If it is a plain string, it is assumed to be a plain column name.
  40. *
  41. * @category Zend
  42. * @package Zend_Db
  43. * @subpackage Expr
  44. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  45. * @license http://framework.zend.com/license/new-bsd New BSD License
  46. */
  47. class Zend_Db_Expr
  48. {
  49. /**
  50. * Storage for the SQL expression.
  51. *
  52. * @var string
  53. */
  54. protected $_expression;
  55. /**
  56. * Instantiate an expression, which is just a string stored as
  57. * an instance member variable.
  58. *
  59. * @param string $expression The string containing a SQL expression.
  60. */
  61. public function __construct($expression)
  62. {
  63. $this->_expression = (string) $expression;
  64. }
  65. /**
  66. * @return string The string of the SQL expression stored in this object.
  67. */
  68. public function __toString()
  69. {
  70. return $this->_expression;
  71. }
  72. }