我使用SQL server2008
作为数据库,我在MSSQL Server 2008
编写了存储过程。它在MSSQL Server 2008
中运行良好。我想从codeigniter
调用此存储过程。为此我写了这样的代码:
phpService.php:
public function Login($username, $password)
{
$this->load->model('Apimodel');
$result = $this->Apimodel->Login($username,$password);
header('Content-type: application/json');
echo json_encode(array('LoginResponce'=>$result));
}
apimodel.php:
function Login($UserName,$Password)
{
$this->db = $this->GetDB();
$query = $this->db->query("EXEC Login");
return $query->result();
}
当我执行没有参数的程序时,工作正常
function Login($UserName,$Password)
{
$this->db = $this->GetDB();
$query = $this->db->query("EXEC Login '$UserName','$Password'");
return $query->result();
}
但是,当我使用参数执行过程时它不起作用
谁能告诉我,我在这里失踪了什么?
提前致谢
答案 0 :(得分:1)
首先,如果您使用Codeigniter,我建议使用他们的数据库类连接到MSSQL Server。您可以在此处详细了解:http://ellislab.com/codeigniter/user-guide/database/configuration.html
如果您没有自动连接到数据库,可以这样连接:$this->load->database('default');
完成配置设置后,您可以在模型中使用这样的功能:
function login($username, $password) {
return $this->db->query("EXEC spLogin '$username', '$password'")->result();
}
答案 1 :(得分:0)
哦..............经过长时间的RND我得到了答案
<强> PhpService.php:强>
public function Login($username, $password)
{
$this->load->model('Apimodel');
$result = $this->Apimodel->Login($username,$password);
header('Content-type: application/json');
echo json_encode(array('LoginResponce'=>$result));
}
<强> apimodel.php:强>
function Login($username, $password)
{
$this->db = $this->GetDB();
$query = $this->db->query("EXEC Login $username,$password");
return $query->result();
}