PHP SQL STMT SELECT multiple LIKE ? is it possible?

前端 未结 2 1348
死守一世寂寞
死守一世寂寞 2021-01-29 05:43
SELECT * 
FROM datatable 
WHERE Name LIKE ? 
OR Code LIKE ? 
OR Date LIKE ? 
OR Inserter LIKE ? 
AND ID = \'2\'

There is an error in php

相关标签:
2条回答
  • 2021-01-29 06:27

    You have 4 ? parameters and you are binding only one value

    $stmt->bind_param("s", $param_term); 
    

    This should be

    $stmt->bind_param("ssss", $param_term,
                            $param_term,
                            $param_term,
                            $param_term); 
    

    so that each parameter ? gets a value.

    Also the query will need bracket to work correctly like this

    WHERE (Name LIKE ? 
        OR Code LIKE ? 
        OR Date LIKE ? 
        OR Inserter LIKE ? ) 
    AND ID = '2'
    
    0 讨论(0)
  • 2021-01-29 06:32

    If you want to transfer strictly one copy of parameter into the query (assuming that you search the same pattern) you may use

    SELECT * 
    FROM datatable 
    WHERE CONCAT_WS(CHAR(X), Name,Code,Date,Inserter) LIKE ? 
    AND ID = '2'
    

    where CHAR(x) is any char which cannot be found in a field or in a pattern.

    0 讨论(0)
提交回复
热议问题