代码之家  ›  专栏  ›  技术社区  ›  dokgu

在CodeIgniter for Oracle中设置数据库架构

  •  2
  • dokgu  · 技术社区  · 6 年前

    我正试着学习CodeIgniter,只是把我的手弄脏了 model

    $this->db->query(); 相反。

    SELECT * FROM schema.table_name . 我想避免写东西 schema. 我需要参考的所有表格。

    我浏览了文件,看到 a configuration for setting schemas 不过,它似乎只与PostgreSQL和ODBC驱动程序一起使用。我还是试过了,但当然没有达到我的预期效果。我仍然收到一个错误,说找不到表。

    我以我的用户身份登录,但我需要以其他用户身份运行查询-即以 user1 但需要以 user2.table_name .

    1 回复  |  直到 6 年前
        1
  •  1
  •   dokgu    6 年前

    所以我可以通过添加一个 __construct()

    class My_model extends CI_Model {
      public function __construct() {
        $this->db->query("ALTER SESSION SET CURRENT_SCHEMA = my_schema");
      }
    
      public function get_awesome_user() {
        $this->db->select("u.username, u.firstname, u.lastname");
        $this->db->from("sys_users u");
        $this->db->where("u.username", $this->input->post("username"));
    
        $query = $this->db->get();
        return $query->result();
      }
    }