2014-02-11 45 views
0

以下是我的查询,我想调用PHP substr();在Mysqlquery中。显然, substr(ident.secondName,-2,2)正在工作,但substr(ident.FirstName,0,2)不起作用。 谢谢您的提前!我可以在Mysql Query中使用PHP函数吗?

mysqli_query($con, "select * from ident where ident.FirstName LIKE '%$first_name%' 
OR substr(ident.FirstName, 0, 2) = '$first_two' OR ident.FirstName IS NULL AND 
(ident.SecondName LIKE '%$second_name%' OR substr(ident.SecondName, -2, 2) 
= $second_two' OR ident.SecondName IS NULL)"); 
+0

together.If要使用PHP函数,然后使用PHP变量不能混用PHP函数和MySQL变量,否则使用MySQL的功能与MySQL varaible only.In查询您要使用PHP函数'SUBSTR '用mysql变量这是错误的 – krishna

回答

0

你打算把查询传给你的Mysql实例,它不会识别PHP代码。所以这是一个不。

2

号不能的MySQL中使用PHP函数。

0

为什么不在MySql中使用函数'SUBSTRING'?

SUBSTRING('stackoverflow', 1, 5) 
result : stack 

SUBSTRING('stackoverflow', -13, 5) 
result : stack 

SUBSTRING('stackoverflow', 6) 
result : overflow 

SUBSTRING('stackoverflow', -8) 
result : overflow 
相关问题