I have the following query that works right in 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. I get records that dsrequestStatusID are 4, which should not be the case.
Here is the query that I use in 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?
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.