【问题标题】:How to use plain SQL in Kohana 3.x如何在 Kohana 3.x 中使用纯 SQL
【发布时间】:2010-10-28 16:49:04
【问题描述】:

我不想依赖 Kohana 3.x 中的所有那些 ORM/Querybuilder 等工具。我只想使用普通的旧 SQL 在我的 MySQL 数据库表中插入新行。

我该怎么做?

【问题讨论】:

    标签: sql mysql kohana-3


    【解决方案1】:

    您可以使用 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
    

    More info

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多