public function showSingleVisit(){
//echo $this->doctorID; the printed 1111
//$this->doctorID = 1111;
$db = connect_db();
$query = "SELECT * FROM visit WHERE doctorID = :doctorID";
$result = $db->prepare($query);
$result->bindParam(':doctorID', $this->doctorID);
$result->execute();
return $result;
}
此查询不会返回任何行,但在放置$this->doctorID = 1111
时,我会获得所需的行。我在此类的bindParam
查询中使用INSERT
并正常工作。问题是什么?
更新:
class visit{
//define public varibles
public function showSingleVisit(){
$db = connect_db();
$query = "SELECT * FROM visit WHERE visit = 0 AND doctorID = :doctorID AND patientID = :patientID";
$result = $db->prepare($query);
$result->bindParam(':patientID', $this->patientID);
$result->bindParam(':doctorID', $this->doctorID);
$result->execute();
return $result;
}
}
以下是我如何通过其他页面调用该功能:
$visit = new visit;
$visit->doctorID = $auth->user->IDNo;
$visit->caseNo = $_SESSION['caseNo'];
$result = $visit->showSingleVisit();
if($result){
while($row = $result->fetch()){
echo'<p>
<label>Date:</label>
<span>'.$row->visitDate.'</span>
</p>';
}
}
else{
echo "No exists!";
}
它既没有显示任何日期,也没有打印&#34;不存在!&#34;。
答案 0 :(得分:1)
你必须指定参数的类型:
$result->bindParam(':doctorID', $this->doctorID, PDO::PARAM_INT);
看这里:
http://php.net/manual/fr/pdostatement.bindparam.php
答案 1 :(得分:1)
因为doctorID是整数,所以应该将data_type添加到INT。它看起来像这样
$result->bindParam(':doctorID', $this->doctorID, PDO::PARAM_INT);