致命错误:无法通过%$ name%中的引用传递参数2

时间:2013-07-17 08:14:02

标签: php mysql

    $query = "
         SELECT 
             id,
             overskrift,
             tekst,
             detaljer,
             varenummer,
             lager,
             vegt,
             pris,
             billede,
             fallow_id
         FROM davidsen_vare
         WHERE 
             overskrift LIKE ? OR varenummer  LIKE ?)
         LIMIT 30";

    $Statement = $this->mysqli->prepare($query);
    $Statement->bind_param("ss","%$sogning%","%$sogning%");   //error here
    $Statement->execute();
    $Statement->bind_result($id,$overskrift,$tekst,$detaljer,$varenummer,$lager,$vegt,$pris,$billede,$fallow_id);

有人可以帮忙吗

1 个答案:

答案 0 :(得分:2)

 $query = "
SELECT 

    id,
    overskrift,
    tekst,
    detaljer,
    varenummer,
    lager,
    vegt,
    pris,
    billede,
    fallow_id
FROM davidsen_vare

WHERE 
( overskrift LIKE %?%
   OR varenummer  LIKE %?%)
   LIMIT 30";

    $Statement = $this->mysqli->prepare($query);
   $Statement->bind_param("ss",$sogning,$sogning);  

OR

 $query = "
SELECT 

    id,
    overskrift,
    tekst,
    detaljer,
    varenummer,
    lager,
    vegt,
    pris,
    billede,
    fallow_id
FROM davidsen_vare

WHERE 
( overskrift LIKE ?
   OR varenummer  LIKE ?)
   LIMIT 30";

    $Statement = $this->mysqli->prepare($query);
    $Statement->bind_param("ss",'%'.$sogning.'%','%'.$sogning.'%');