我放在php中的sql
$sql = 'select * from table_1 where Right(col_1, LOCATE('.',col_1))';
但是,那 '。' $sql 会变成
select * from table_1 where Right(col_1, LOCATE(,col_1))
因为'.'
如何呈现“。” , 当我把它放在 php
这应该像...
$sql = "select * from table_1 where (col_1, LOCATE('.', col_1))";
在您的情况下,您是concatenating
两个字符串-
select * from table_1 where (col_1, LOCATE(
,col_1))
在字符串周围使用双引号
$sql = "select * from table_1 where (col_1, LOCATE('.',col_1))";
您可以使用转义字符
$sql = 'select * from table_1 where (col_1, LOCATE(\'.\',col_1))';
或者您可以对 php 使用双引号
$sql = "select * from table_1 where (col_1, LOCATE('.',col_1))";
简单的:
$sql = "select * from table_1 where (col_1, LOCATE('.',col_1))";
使用双引号:)
为您的陈述使用双引号或转义单引号。
$sql = "select * from table_1 where (col_1, LOCATE('.',col_1))";
或者
$sql = 'select * from table_1 where (col_1, LOCATE(\'.\',col_1))';
这是另一种方法:(连接)
$sql = 'select * from table_1 where (col_1, LOCATE('.'.,col_1))';
试试这个
$sql = sprintf("select * from table_1 where (col_1, LOCATE('%s',col_1))",
mysql_real_escape_string('.'));