Write native SQL in CI (package query)

Source: Internet
Author: User
Package Query

Encapsulation allows you to simplify your query syntax by having the system assemble individual query statements for you. Take the following example:

$sql = "SELECT * FROM some_table WHERE id = ? AND status = ? AND author = ?";

$this->db->query($sql, array(3, ‘live‘, ‘Rick‘));

The question mark in the query statement is automatically replaced by the value in the array of the second parameter where the query function is located.

The second benefit of using encapsulated queries is that all values are automatically escaped, resulting in a more secure query statement. You do not have to manually escape the data, and the controller will do it for you automatically.

Note: If you have only one parameter, you can simply write the variable without using the array.

Write native SQL in CI (package query)

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.