[英]SELECT * FROM Table WHERE Column LIKE %?%
Based on information here MySQL query String contains trying 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 %?
Nothing works. 什么都行不通。 Get error 得到错误
Syntax error or access violation: 1064 You have an error in your SQL syntax; 语法错误或访问冲突:1064 SQL语法中有错误; check the manual that corresponds to your MySQL server version for the right syntax to use near '%... 查看与您的MySQL服务器版本对应的手册,以便在'%...附近使用正确的语法
Tried with SELECT * FROM Table WHERE Column LIKE ?
尝试SELECT * FROM Table WHERE Column LIKE ?
but this is not for contains
但这不适用于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 ( ?
)? 什么是正确的pdo contains
位置占位符的声明( ?
)?
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...
after like add quotes. 之后添加引号。 eg:- like '%?%'
例如: - like '%?%'
ie: 即:
SELECT * FROM table_name WHERE column_name like '%field_name%';
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 希望这可以帮助
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. 为null,因为连接将产生null。 you could use coalesce 你可以使用coalesce
SELECT * FROM Table WHERE Column LIKE '%' + Coalesce(?,'') + '%'
SELECT * FROM Table WHERE Column LIKE Coalesce(?,'') + '%'
SELECT * FROM Table WHERE Column LIKE '%' + Coalesce(?,'')
如果您想使用预准备语句,请查看http://php.net/manual/de/pdo.prepared-statements.php 。
SELECT * FROM REGISTRY where name LIKE '%?%'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.