Reputation:
I have a table value as below string:
PhysicalAddress:E8-6A-64-DE-48-60PhysicalAddress:04-EA-56-08-E6-8EPhysicalAddress:04-EA-56-08-E6-8FPhysicalAddress:06-EA-56-08-E6-8EPhysicalAddress:04-EA-56-08-E6-92
I get value as random/shuffle order as below to verify if they are exactly matched to the table value:
PhysicalAddress:E8-6A-64-DE-48-60PhysicalAddress:04-EA-56-08-E6-8EPhysicalAddress:04-EA-56-08-E6-8FPhysicalAddress:06-EA-56-08-E6-8EPhysicalAddress:04-EA-56-08-E6-92
or
PhysicalAddress:04-EA-56-08-E6-92PhysicalAddress:E8-6A-64-DE-48-60PhysicalAddress:04-EA-56-08-E6-8EPhysicalAddress:04-EA-56-08-E6-8FPhysicalAddress:06-EA-56-08-E6-8E
or
PhysicalAddress:06-EA-56-08-E6-8EPhysicalAddress:04-EA-56-08-E6-92PhysicalAddress:E8-6A-64-DE-48-60PhysicalAddress:04-EA-56-08-E6-8EPhysicalAddress:04-EA-56-08-E6-8F
or
PhysicalAddress:04-EA-56-08-E6-8FPhysicalAddress:06-EA-56-08-E6-8EPhysicalAddress:04-EA-56-08-E6-92PhysicalAddress:E8-6A-64-DE-48-60PhysicalAddress:04-EA-56-08-E6-8E
or
PhysicalAddress:04-EA-56-08-E6-8EPhysicalAddress:04-EA-56-08-E6-8FPhysicalAddress:06-EA-56-08-E6-8EPhysicalAddress:04-EA-56-08-E6-92PhysicalAddress:E8-6A-64-DE-48-60
Tried:
select *from table1 where preview like '%PhysicalAddress:04-EA-56-08-E6-8EPhysicalAddress:04-EA-56-08-E6-8FPhysicalAddress:06-EA-56-08-E6-8EPhysicalAddress:04-EA-56-08-E6-92PhysicalAddress:E8-6A-64-DE-48-60%' limit 1;
But it is not correct SQL, the input value is random, shuffled where the database value is fixed, i need to match random,shuffled input matching with fixed database value. How to make it very stable?
Upvotes: 0
Views: 67
Reputation: 147236
One way to do this is to split the incoming string into the separate addresses and then check that they all match the table value:
$string = 'PhysicalAddress:E8-6A-64-DE-48-60PhysicalAddress:04-EA-56-08-E6-8EPhysicalAddress:04-EA-56-08-E6-8FPhysicalAddress:06-EA-56-08-E6-8EPhysicalAddress:04-EA-56-08-E6-92';
$components = str_split($string, 33);
$query = "SELECT *
FROM table1
WHERE preview LIKE '%" . implode("%'\n AND preview LIKE '%", $components) . "%'";
echo $query;
Output:
SELECT *
FROM table1
WHERE preview LIKE '%PhysicalAddress:E8-6A-64-DE-48-60%'
AND preview LIKE '%PhysicalAddress:04-EA-56-08-E6-8E%'
AND preview LIKE '%PhysicalAddress:04-EA-56-08-E6-8F%'
AND preview LIKE '%PhysicalAddress:06-EA-56-08-E6-8E%'
AND preview LIKE '%PhysicalAddress:04-EA-56-08-E6-92%'
Upvotes: 1