【发布时间】:2010-10-28 16:49:04
【问题描述】:
我不想依赖 Kohana 3.x 中的所有那些 ORM/Querybuilder 等工具。我只想使用普通的旧 SQL 在我的 MySQL 数据库表中插入新行。
我该怎么做?
【问题讨论】:
我不想依赖 Kohana 3.x 中的所有那些 ORM/Querybuilder 等工具。我只想使用普通的旧 SQL 在我的 MySQL 数据库表中插入新行。
我该怎么做?
【问题讨论】:
您可以使用 DB::query($type, $sql) 方法创建 Database_Query 对象:
$sql = "INSERT INTO table(column1, column2) VALUES(:value1, :value2)";
$result = DB::query(Database::INSERT, $sql)->bind(':value1', $val1)->bind(':value2', $val2)->execute();
echo $result[0]; // last_insert_id
echo $result[1]; // total rows inserted
【讨论】: