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);
}
}
精彩评论