Why CakePHP forms INSERT statement with 'CURRENT_TIMESTAMP' in quotes?
I'm getting this error, because cakephp 1.3.11 creates an INSERT statement with 'CURRENT_TIMESTAMP' in quotes. Similar thing worked in 1.3.9. What might I be doing wrong?
SQL Error: 1292: Incorrect datetime value: 'CURRENT_TIMESTAMP' for column 'time_posted' at row 1 [CORE\cake\libs\model\datasources\dbo_source.php, line 684]
This is the context query:
$sql = "INSERT INTO `my_table` (`time_posted`, `version`, `provider`, `date`) VALUES ('CURRENT_TIMESTAMP', 0, 'provider', '2011-08-03 16:11:00')"
I'm trying to create a new record in database from cakephp using this code:
class MyTable extends AppModel
{
...
function blah() {
...
$this->create()
$ret=$this->save(array('MyTable'=>array('provider'=>$provider,'date'=>$datetime)));
...
here's the stack:
DboSource::showQuery() - CORE\cake\libs\model\datasources\dbo_source.php, line 684
DboSource::execute() - CORE开发者_如何学Python\cake\libs\model\datasources\dbo_source.php, line 266
DboSource::create() - CORE\cake\libs\model\datasources\dbo_source.php, line 752
Model::save() - CORE\cake\libs\model\model.php, line 1342
MyTable::add() - APP\models\my_table.php, line 1288
As Dunhamzzz said, there must be a place causing CURRENT_TIMESTAMP to be inserted.
Once you find it, you can use date('Y-m-d H:i:s')
to save using the current time.
Or, if you want to do it using SQL, you can use DboSource::expression('NOW()')
.
ie.
array('MyTable'=>array('time_posted' => DboSource::expression('NOW()')))
精彩评论