douqiang4501
2013-06-21 08:29
浏览 571
已采纳

SELECT * FROM表WHERE列LIKE%?%

Based on information here MySQL query String contains trying to create pdo query with ?

Experimented with following

SELECT * FROM Table WHERE Column LIKE %?%

SELECT * FROM Table WHERE Column LIKE ?%

SELECT * FROM Table WHERE Column LIKE %?

Nothing works. Get error

Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%...

Tried with SELECT * FROM Table WHERE Column LIKE ? but this is not for contains

Aim is to get query SELECT * FROM Table WHERE Column contains ?

What is is correct pdo contains statement for positional placeholders (?)?

图片转代码服务由CSDN问答提供 功能建议

根据此处的信息 MySQL查询字符串包含 trying使用创建pdo查询?

使用以下实验 \ n

SELECT * FROM表WHERE列LIKE%?%

SELECT * FROM表WHERE列LIKE?%

SELECT * FROM表WHERE列LIKE%?

没有任何作用。 获取错误

语法错误或访问冲突:1064 SQL语法中出错; 检查与MySQL服务器版本对应的手册 ,以便在'%... 下使用正确的语法

尝试使用 SELECT * FROM Table WHERE列LIKE?但这不适用于 contains

目标是获取查询 SELECT * FROM Table WHERE Column包含?

什么是正确的pdo 包含位置占位符的语句()?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

5条回答 默认 最新

  • dongsonglian7303 2013-06-21 08:34
    已采纳

    try this by concatenating the value in the string via PHP,

    $value = "valueHere";
    $passThis = "%" . $value . "%";
    // other pdo codes...
    $stmt = $dbh->prepare("SELECT * FROM Table WHERE Column LIKE ?");
    $stmt->bindParam(1, $passThis);
    // other pdo codes...
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • dongwei4096 2013-06-21 08:32

    after like add quotes. eg:- like '%?%'

    i.e:

    SELECT * FROM table_name WHERE column_name like '%field_name%';
    
    评论
    解决 无用
    打赏 举报
  • duanhemou9834 2013-06-21 08:34

    If you would like to use prepared statements then take a look at http://php.net/manual/de/pdo.prepared-statements.php.

    SELECT * FROM REGISTRY where name LIKE '%?%'
    
    评论
    解决 无用
    打赏 举报
  • dongshuao2309 2013-06-21 08:40

    I think wildcard stament should be within single quotes, like;

    SELECT * FROM Table WHERE Column LIKE '%?%';
    

    This returns any record which contains the string given anywhere within the particular column field

    Column data which starts with 'ber', example

    SELECT * FROM Table WHERE Column LIKE 'ber%';
    

    Hope this helps

    评论
    解决 无用
    打赏 举报
  • dongtan3395 2013-06-21 08:44

    Either put the % characters before and after your parameter before you pass it into the query or

    SELECT * FROM Table WHERE Column LIKE '%' + ? + '%'
    
    SELECT * FROM Table WHERE Column LIKE ? + '%'
    
    SELECT * FROM Table WHERE Column LIKE '%' + ?
    

    Although this will fail if ? is null because the concatenate will yield null. you could use coalesce

    SELECT * FROM Table WHERE Column LIKE '%' + Coalesce(?,'') + '%'
    
    SELECT * FROM Table WHERE Column LIKE Coalesce(?,'') + '%'
    
    SELECT * FROM Table WHERE Column LIKE '%' + Coalesce(?,'')
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题