美好的一天伙计们,
我需要一点帮助吗? 我有使用PDO的代码,在我的PHP文件中,让我们说这个文件是我的controller.php,我只用类调用我的函数。 在我的php文件中,我有一个可变的硬编码client_id。我想要的是获取硬编码的值并传递给我的类函数由sql查询触发。这是我的controller.php的代码 require_once(' ../../../服务/机器人/ Glabs / globe_smsin.php&#39);
Controller.php这样 $ client_id =" 1";
$ clients = new GetClients(); echo $ clients-> GetClients();
这是我的服务代码
class GetClients{
private $db;
private $conn;
public function __construct(){
$this->db = new MySQL();
$this->conn = $this->db->Connect();
}
public function GetClients(){
$conn = $this->conn;
$query = "SELECT
id, client_name, globe_shortcode, globe_app_id, globe_app_secret, globe_charging_amount,
chikka_shortcode, chikka_client_id, chikka_secret_key, chikka_request_cost
FROM clients
WHERE id = ".$client_id."
ORDER BY id DESC";
try{
$stmt = $conn->prepare($query);
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
if(sizeof($result) > 0){
foreach($result as $row){
$fetchdata = (object)$row;
$returndata[] = array(
"id"=>$fetchdata->id,
"client_name"=>$fetchdata->client_name,
"globe_shortcode"=>$fetchdata->globe_shortcode,
"globe_app_id"=>$fetchdata->globe_app_id,
"globe_app_secret"=>$fetchdata->globe_app_secret,
"globe_charging_amount"=>$fetchdata->globe_charging_amount,
"chikka_shortcode"=>$fetchdata->chikka_shortcode,
"chikka_client_id"=>$fetchdata->chikka_client_id,
"chikka_secret_key"=>$fetchdata->chikka_secret_key,
"chikka_request_cost"=>$fetchdata->chikka_request_cost
);
}
return json_encode($returndata);
}else{
return "null";
}
}catch(PDOException $e){
// return "General Error";
echo $e->GetMessage();
}
}
}
感谢那些能帮助我的人