在多个数据库连接中生成查询(codeigniter php)帮助

发布于 2024-11-06 01:54:24 字数 1437 浏览 0 评论 0原文

Assalamualaykum :)

当我想在 codeigniter 中生成查询时遇到麻烦, 这是代码:

class Pengadilan_negeri extends CI_Controller {

    private function get_database_configuration($database_name) {
        $configuration = array(
            'hostname' => "DREAMBENDER\PENGADILANNEGERI",
            'username' => "sa",
            'password' => "12111993",
            'dbdriver' => "mssql"
        );

        $database_configuration = NULL;

        if ($database_name == "pidana") {
            $database_configuration = $configuration + array('database' => "dataPidana");
        } else if ($database_name == "perdata") {
            $database_configuration = $configuration + array('database' => "dataPerdata");
        }

        return $database_configuration;
    }

    public function biasa() {

        $DB1 = $this->load->database($this->get_database_configuration("pidana"), TRUE);
        $DB2 = $this->load->database($this->get_database_configuration("perdata"), TRUE);

        $DB1->query("SELECT * FROM dbo.DATA_REGISTER");

        foreach ($DB1->result() as $row) {
            print_r($row);
        }
    }
}

并且有一些像这样的错误输出:

Fatal error: Call to undefined method CI_DB_mssql_driver::result() in E:\xampp\htdocs\pengadilan_negeri\application\controllers\register_perkara\perkara_pidana.php on line 33

我应该做什么才能使此代码运行没有错误?

Assalamualaykum :)

i have trouble when i want to generate a query in codeigniter,
here is the code :

class Pengadilan_negeri extends CI_Controller {

    private function get_database_configuration($database_name) {
        $configuration = array(
            'hostname' => "DREAMBENDER\PENGADILANNEGERI",
            'username' => "sa",
            'password' => "12111993",
            'dbdriver' => "mssql"
        );

        $database_configuration = NULL;

        if ($database_name == "pidana") {
            $database_configuration = $configuration + array('database' => "dataPidana");
        } else if ($database_name == "perdata") {
            $database_configuration = $configuration + array('database' => "dataPerdata");
        }

        return $database_configuration;
    }

    public function biasa() {

        $DB1 = $this->load->database($this->get_database_configuration("pidana"), TRUE);
        $DB2 = $this->load->database($this->get_database_configuration("perdata"), TRUE);

        $DB1->query("SELECT * FROM dbo.DATA_REGISTER");

        foreach ($DB1->result() as $row) {
            print_r($row);
        }
    }
}

and the're some error output like this :

Fatal error: Call to undefined method CI_DB_mssql_driver::result() in E:\xampp\htdocs\pengadilan_negeri\application\controllers\register_perkara\perkara_pidana.php on line 33

what should i do to make this code running without errors ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冷月断魂刀 2024-11-13 01:54:24

如果您使用 MSSQL,请在您的配置数据库中使用端口,如下所示:
'端口' => “1433”,
1433是默认端口

if u using MSSQL please use port in your config db like this:
'port' => "1433",
1433 is a default port

爱格式化 2024-11-13 01:54:24

在您的 biasa() 函数中像这样更改您的查询。

public function biasa() {

    $DB1 = $this->load->database($this->get_database_configuration("pidana"), TRUE);
    $DB2 = $this->load->database($this->get_database_configuration("perdata"), TRUE);

    // execute the query and store it
    $query_db1 = $DB1->query("SELECT * FROM dbo.DATA_REGISTER");

    // call ->result() on the executed query to retrieve the results
    foreach ($query_db1->result() as $row) {
        print_r($row);
    }
}

in your biasa() function change your query like this.

public function biasa() {

    $DB1 = $this->load->database($this->get_database_configuration("pidana"), TRUE);
    $DB2 = $this->load->database($this->get_database_configuration("perdata"), TRUE);

    // execute the query and store it
    $query_db1 = $DB1->query("SELECT * FROM dbo.DATA_REGISTER");

    // call ->result() on the executed query to retrieve the results
    foreach ($query_db1->result() as $row) {
        print_r($row);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文