How does CakePHP write MySQL IN conditions?

Source: Internet
Author: User
My code is written in this way {code ...} the final SQL statement is {code ...} this SQL statement is actually wrong. It should be {code ...} how should I write it in the code? My code is written in this way.

$ids = '1,2,3,4';$conditions[]=array('id IN (?)'=> $ids);

The SQL statement is

SELECT ...ooxx... WHERE id IN ('1,2,3,4');

This SQL statement is actually wrong. It should be

SELECT ...ooxx... WHERE id IN (1,2,3,4);

How should I write it in the code?

Reply content:

My code is written in this way.

$ids = '1,2,3,4';$conditions[]=array('id IN (?)'=> $ids);

The SQL statement is

SELECT ...ooxx... WHERE id IN ('1,2,3,4');

This SQL statement is actually wrong. It should be

SELECT ...ooxx... WHERE id IN (1,2,3,4);

How should I write it in the code?

$conditions[] = array(                    'id' => array(1, 2, 3, 4 )                );

You can set an array containing values after the corresponding field name to achieve the same effect as the SQL logic operator IN.

I don't need it for a long time... just pass the array in my memory...

Example...

$this->foo->find( 'all', array(    'conditions' => array( 'foo.bar' => array( 1, 2, 3, 4 ) )) );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.