开发者

generating queries in multiple database connection (codeigniter php) help

开发者 https://www.devze.com 2023-03-04 07:29 出处:网络
Assalamualaykum :) i have trouble when i want to generate a query in codeigniter, here is the code : class Pengadilan_negeri extends CI_Controller {

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 ?


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


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);
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消