Bug Report #545
Database Expression Library
| Status: | Closed | Start date: | ||
|---|---|---|---|---|
| Priority: | Normal | Due date: | ||
| Assignee: | % Done: | 0% |
||
| Category: | Libraries:Database | |||
| Target version: | 2.3.2 | |||
| Resolution: | fixed | Points: |
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.
History
Updated by Woody Gilk over 3 years ago
- Status changed from New to Assigned
Updated by Woody Gilk over 3 years ago
- Status changed from Assigned to Closed
- Resolution set to fixed
Updated by John Heathco almost 3 years ago
- Status changed from Closed to Feedback
- Resolution deleted (
fixed)
Updated by John Heathco almost 3 years ago
- Status changed from Feedback to Closed
- Resolution set to fixed