简体   繁体   English

查询在sql中有效,但在php中无效

[英]Query works in sql but not in php

I have the following query that works right in sql 我有以下查询在SQL中正常工作

SELECT *
FROM `dsrequest`
WHERE dsrequeststatusID NOT IN ('4', '5', '6')
AND CASE
WHEN ('Κ' REGEXP '^[0-9]+$')  THEN
dsrequestClientAfm LIKE 'Κ%'
ELSE
( dsrequestClientFirstName LIKE 'Κ%' OR  dsrequestClientLastName LIKE 'Κ%' OR  dsrequestClientEmail LIKE 'Κ%'  )
END

but when I place it in the php using variable instead of 'K' gives me wrong set of results, that is it seems that where part doesn't work at all. 但是,当我使用变量而不是'K'将其放置在php中时,会给我错误的结果集,似乎其中的一部分根本不起作用。 I get records that dsrequestStatusID are 4, which should not be the case. 我得到dsrequestStatusID为4的记录,事实并非如此。

Here is the query that I use in php: 这是我在php中使用的查询:

$this->db->query("SELECT *
FROM `dsrequest`
WHERE dsrequeststatusID NOT IN ('4', '5','6')
AND CASE
WHEN ('$searchString' REGEXP '^[0-9]+$')  THEN
dsrequestClientAfm LIKE '$searchString%'
ELSE
( dsrequestClientFirstName LIKE '$searchString%' OR  dsrequestClientLastName LIKE '$searchString%' OR  dsrequestClientEmail LIKE '$searchString%'  )
END");

Anyone can spot the mistake? 任何人都可以发现错误?

UPDATE: 更新:

After the suggestion I manage to print the query, and it is the same 在建议之后,我设法打印查询,这是相同的

SELECT * FROM `dsrequest` 
WHERE dsrequeststatusID NOT IN ('4', '5','6') 
AND CASE 
WHEN ('Κ' REGEXP '^[0-9]+$') THEN 
dsrequestClientAfm LIKE 'Κ%' 
ELSE 
( dsrequestClientFirstName LIKE 'Κ%' OR dsrequestClientLastName LIKE 'Κ%' OR dsrequestClientEmail LIKE 'Κ%' ) 
END

Anyone can spot any difference that I can't? 任何人都可以发现我无法做到的任何差异? Is the regular expression the issue? 正则表达式是问题吗? Did they have any difference between sql and php? 他们在sql和php之间有什么区别吗?

Sorry for putting you all of you in trouble. 抱歉给大家带来麻烦。 Problem was elsewhere with my codeigniter code, not with the query. 问题出在我的代码初始化代码的其他地方,而不是查询。 As soon as I fixed that, query now works like a charm. 一旦我解决了这个问题,查询现在就像一个超级按钮。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM