How to use explode mysql function in where condition with cakephp I am using cakephp 2.6. I have payment_method fields in mysql table which store the values like 54,52,59,57 . 

Now my question is that how can i check if new posted payment method id is available in  the payment_method value.

Here $data['PaymentMaster']['payment_method'] = 52

$paymentDetail = $this-&gt;PaymentMaster-&gt;find('first',array('conditions'=&gt;array('NOT' =&gt; array('payment_method'=&gt;$data['PaymentMaster']['payment_method']))));


I want to check if value not in database then add in to database other wise fire an error that Error: The rule is contradicting with the other rule, please check the rule.

Any help would be appreciated. Thanks in advance
by Unique constraint on your payment_method field, you can make sure that payment_method is unique. If the peyment_method is already exists, it will throw a SQL Error.


  Duplicate entry 'x' for key 'peyment_method'


The SQL for that would be:

ALTER TABLE YourTableName ADD UNIQUE (payment_method)


But if you mean you need to make sure this payment_method exists and the payment_method_id is in another table, you need foreign key.

ALTER TABLE YourTable ADD FOREIGN KEY `methodidCheck`(payment_method)
REFERENCES payment_method_table(payment_method_id);


Hope I got your question right