在多个数据库连接中生成查询(codeigniter php)帮助
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用 MSSQL,请在您的配置数据库中使用端口,如下所示:
'端口' => “1433”,
1433是默认端口
if u using MSSQL please use port in your config db like this:
'port' => "1433",
1433 is a default port
在您的
biasa()
函数中像这样更改您的查询。in your
biasa()
function change your query like this.