如何在mysqli prepare语句中插入pourcentage符号%?

时间:2019-05-21 21:29:03

标签: php sql mysqli

我想运行以下代码:

但显示错误。

$stmt = $this->con->prepare("SELECT HEUREDEB , HEUREFIN from reservation 
where ID_EMPL = ? and HEUREDEB like ?%");
            $stmt->bind_param("ss",$ID_EMPL,$HEUREDEB);
            $stmt->execute();
            $result=$stmt->get_result();

1 个答案:

答案 0 :(得分:1)

使用CONCAT()

$stmt = $this->con->prepare("SELECT HEUREDEB , HEUREFIN from reservation 
where ID_EMPL = ? and HEUREDEB like CONCAT(?, '%')");

您也可以将其添加到变量中。

$HEUREDB .= '%';
$stmt = $this->con->prepare("SELECT HEUREDEB , HEUREFIN from reservation 
where ID_EMPL = ? and HEUREDEB like ?");