Ticket #545 (closed Feature Request: fixed)
Database Expression Library
| Reported by: | Ryuuzaki | Owned by: | Shadowhand |
|---|---|---|---|
| Priority: | minor | Milestone: | 2.2 |
| Component: | Libraries:Database | Version: | SVN HEAD |
| Keywords: | Cc: |
Description
By using the following class, database expressions, arithmetic and functions will be possible without modifying any core files.
// librarires/Database_Expr.php
<?php
class Database_Expr
{
private $_value = NULL;
public function __construct($value)
{
$this->_value = $value;
}
public function __toString()
{
return $this->_value;
}
}
for example, the following code:
Database::instance()->update('anime',
array(
'episodes' => new Database_Expr('episodes + 1')
),
array('id' => 1)
);
will produce the following SQL:
UPDATE `anime` SET `episodes` = episodes + 1 WHERE `id` = 1
inserting like:
Database::instance()->insert('anime', array(
'date' => new Database_Expr('NOW()')
));
works as well.
Change History
Note: See
TracTickets for help on using
tickets.
