Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The following code implements the ActiveRecord library in CodeIgniter (though ActiveRecord usually refers to a fairly different way of getting values from a database).</p> <pre><code>$this-&gt;db -&gt;select('*') -&gt;from('table'); $this-&gt;db-&gt;get(); </code></pre> <p>Right until the get() method, ActiveRecord will build and store an SQL query internally, and then, when you call get(), execute that query and replace it with a result object, which you can then access with result(), result_array(), row(), or row_array().</p> <p>The following code will execute an SQL query directly from the $sql argument you give it</p> <pre><code>$this-&gt;db-&gt;query($sql); </code></pre> <p>From that point, if you were SELECTing data from your database, you can do this:</p> <pre><code>$result = $this-&gt;db-&gt;result_array(); </code></pre> <p>to get the results of that query into an array.</p> <p>For pagination, you can use both ways. This, for example, would get the records for a page 3 if you had 10 records per page:</p> <pre><code>$query = $this-&gt;db-&gt;select('*')-&gt;from('table')-&gt;limit(10, 30)-&gt;get(); if($query-&gt;num_rows()) { return $query-&gt;result_array(); } return FALSE; </code></pre> <p>And, if you're using any of the $this->db methods() (where()), CodeIgniter will automatically escape the values you put into it:</p> <pre><code>$this-&gt;db-&gt;where('id', "'i am a nasty piece of SQL';DROP DATABASE 'my_db'"); </code></pre> <p>That would be fine - CodeIgniter takes care of it for you. Just always be aware that just because it's done for you, doesn't mean there aren't other ways to expose security vulnerabilities in your code.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload