Welcome Guest, Not a member yet? Register   Sign In
DB Class / ActiveRecord Question(s)
#1

[eluser]dsentker[/eluser]
Hey there,

- if i use the Active Record class from CI, do i have to check my data before inserting (e.g. mysql_real_escape_string(); ? ) The Userguide is a litte bit disputed in this thing.

- Another Question: How do i select exactly ONE row from my table? I want to select the Row with id=`85`, for example. Is that the right way?

Code:
$query = $this->db->get('news',1,85);

That produces
Code:
SELECT * from 'news' LIMIT 85,1
.

- In a table with many columns, in inefficient and slow. How can i handle the query below with the Active Record class?

Code:
SELECT id,title,date from 'news' LIMIT 85,1
#2

[eluser]JanDoToDo[/eluser]
$this -> db -> from('my_table');
$this -> db -> where('row_id', 85);
$this -> db ->get();

You can combine these statements but I find it easier when starting to do that. The AR class escapes strings automatically. Also, if you are using POST data, if you use $this -> input -> post('data') it will automatically escape the data also . Smile enjoy! Smile
#3

[eluser]JanDoToDo[/eluser]
And as for your 3nd part:
$this -> db -> select('id,title,date');
$this -> db -> limit(85, 1); <<<The first number is the number of rows you want returned and the second is the offset

Do you really want to do this? If you are selecting one row you dont really want to use offset... use what i just posted Smile
#4

[eluser]Phil Sturgeon[/eluser]
Code:
$query = $this->db->select('id,title,date')->get('news',1,85);
#5

[eluser]Colin Williams[/eluser]
Quote:if i use the Active Record class from CI, do i have to check my data before inserting

Very first paragraph of the User Guide's section on Active Record says

Quote:It also allows for safer queries, since the values are escaped automatically by the system.

... which I agree, is totally dubious (or, 'disputed,' as you put it)
#6

[eluser]John_Betong[/eluser]
&nbsp;
Today I discovered from the Profiler Output that selecting a single item from a table is considerably faster if ORDER BY the field is used (maybe not if there is no index on that field but I reckon there should be an index by default).
&nbsp;
Code:
$this -> db -> from     (‘my_table’);
   $this -> db -> where    (‘row_id’, 85);
   $this -> db -> order_by (‘row_id’);
   $this -> db ->get();
&nbsp;
&nbsp;
&nbsp;




Theme © iAndrew 2016 - Forum software by © MyBB