gpt4 book ai didi

php - 使用 Sqlsrv 驱动程序从存储过程中获取数据

转载 作者:可可西里 更新时间:2023-11-01 13:30:37 25 4
gpt4 key购买 nike

我正在使用 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();

}

但是,当我使用参数执行过程时它不起作用

谁能告诉我我在这里错过了什么?

提前致谢

最佳答案

首先,如果您使用的是 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();
}

关于php - 使用 Sqlsrv 驱动程序从存储过程中获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18567150/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com