如何在数据库中插入对象

时间:2011-08-19 07:00:06

标签: kohana-3

如何在kohana 3中的数据库中插入对象?

我的代码是:

$application = DB::query(Database::SELECT,"SELECT * FROM application_settings WHERE 'id'  = 1")->as_object()->execute();
$application -> google_analytical = $_POST['google_txt'];
$application = DB::insert('application_settings',$application)->execute();
$this->template->inner->status_msg = "Record has been saved successfully";

我想将名为application的对象插入数据库。

1 个答案:

答案 0 :(得分:0)

DB::insert() syntax是:

DB::insert('application_settings', $application_columns)
   ->values($application_values)
   ->execute();

顺便说一下,为什么要插入新记录而不是UPDATE现有记录?

DB::update('application_settings')
   ->set(array('google_analytical' => $_POST['google_txt']))
   ->where('id', '=', $application->id))
   ->execute();

<强> UPD 即可。您正在寻找一行,所以:

// insert it after DB::query() call
$application = current($application);