php SELECT * FROM Table WHERE Column LIKE %?%
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17230771/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SELECT * FROM Table WHERE Column LIKE %?%
提问by user2465936
Based on information here MySQL query String containstrying to create pdo query with ?
基于此处的信息MySQL 查询字符串包含尝试创建 pdo 查询?
Experimented with following
尝试了以下
SELECT * FROM Table WHERE Column LIKE %?%
SELECT * FROM Table WHERE Column LIKE %?%
SELECT * FROM Table WHERE Column LIKE ?%
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 '%...
语法错误或访问冲突:1064 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在 '%...
Tried with SELECT * FROM Table WHERE Column LIKE ?
but this is not for contains
尝试过,SELECT * FROM Table WHERE Column LIKE ?
但这不是为了contains
Aim is to get query SELECT * FROM Table WHERE Column contains ?
目的是获取查询 SELECT * FROM Table WHERE Column contains ?
What is is correct pdo contains
statement for positional placeholders (?
)?
contains
位置占位符 ( ?
) 的正确 pdo语句是什么?
回答by John Woo
try this by concatenating the value in the string via PHP,
通过 PHP 连接字符串中的值来尝试这个,
$value = "valueHere";
$passThis = "%" . $value . "%";
// other pdo codes...
$stmt = $dbh->prepare("SELECT * FROM Table WHERE Column LIKE ?");
$stmt->bindParam(1, $passThis);
// other pdo codes...
回答by ejo
after like add quotes. eg:- like '%?%'
后喜欢加引号。例如:-like '%?%'
i.e:
IE:
SELECT * FROM table_name WHERE column_name like '%field_name%';
回答by WattoWatto
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
以“ber”开头的列数据,示例
SELECT * FROM Table WHERE Column LIKE 'ber%';
Hope this helps
希望这可以帮助
回答by Bob Vale
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(?,'')
回答by Tony Stark
If you would like to use prepared statements then take a look at http://php.net/manual/de/pdo.prepared-statements.php.
如果您想使用准备好的语句,请查看http://php.net/manual/de/pdo.prepared-statements.php。
SELECT * FROM REGISTRY where name LIKE '%?%'