PHP用LIKE编写语句

时间:2018-05-28 13:57:19

标签: php mysql mysqli prepared-statement

我正在使用:

   $ordem = "%".$_GET['ordem']."%"; 
    $arr = [];

    $stmt = $conn->prepare("SELECT texto,data_hora FROM logs WHERE texto LIKE ?");  
    $stmt->bind_param('s',$ordem);
    $stmt->execute();

$ordem变量正在接收包含在DB中但未找到的值...

出了什么问题?

由于

1 个答案:

答案 0 :(得分:1)

尝试以下代码

$stmt = $conn->prepare("SELECT texto, data_hora FROM logs WHERE texto LIKE '%?%'");  
$stmt->bind_param('s', $_GET['ordem']);

或尝试以下与您所做的相似

$param = "%{$_GET['ordem']}%";
$stmt = $db->prepare("SELECT texto, data_hora FROM logs WHERE texto LIKE ?");
$stmt->bind_param("s", $param);