Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,153,331 members, 7,819,135 topics. Date: Monday, 06 May 2024 at 11:44 AM

Active Records VS Sql What Do You Think ?? - Webmasters - Nairaland

Nairaland Forum / Science/Technology / Webmasters / Active Records VS Sql What Do You Think ?? (721 Views)

I'll Get You 1,000 Active Users For Your App/website For 1,000 Naira / Quick Sql Injection Vulnerability Test / Creating Complex / Advanced Search Forms With Sql Queries In Dreamweaver (2) (3) (4)

(1) (Reply) (Go Down)

Active Records VS Sql What Do You Think ?? by mambenanje(m): 6:57pm On Jun 24, 2008
Active records is a new way of querying a relational database without hand coding or thinking about the sql yourself.
now let me give an example
if I want to get everything in a table of users I will code it like this


//construct the sql
$sql="select * from users order by dateregistered desc";
//execute the query ingnoring the errors
$result=@mysql_query($sql);
/// now fetch
while($record=mysql_fetch_assoc($result)){
echo "username: ".$record['name']."<br>";
}

thats realy boring and I can't remember the last time I wrote codes like that. imagine coding a solution as big as twitter and u have to write such codes. it will take you 4 months.

now lets do it with active records


//instantiate the active records database class
$db=new activeRecordsDB(array('host'=>'localhost','username'=>'root','password=>'passwod'));
//order the query by date registered
$db->orderby('dateregistered','desc');
//execute the query
$records=$db->get('users');
//loop through the records
foreach($records->result() as $user){
echo "name: ". $user->name;
}

with active records we have more readable codes and easy to work on by many other developers. nowadays I work with projects with guys in India and Europe with active records our codes are easy to comprehend.
active records information can be read from wikipedia following this link http://en.wikipedia.org/wiki/Active_record
Re: Active Records VS Sql What Do You Think ?? by mambenanje(m): 10:40pm On Jun 26, 2008
well something I didnt add is how to add WHERE, LIKE condition statements using active records
- they are done as shown below

/instantiate the active records database class
$db=new activeRecordsDB(array('host'=>'localhost','username'=>'root','password=>'passwod'));

//add a where clause
$db->where('name','%churchill%');
//or add a like clause
$db->like('website','%afrovisiongroup.com%');


//order the query by date registered
$db->orderby('dateregistered','desc');
//execute the query
$records=$db->get('users');
//loop through the records
foreach($records->result() as $user){
echo "name: ". $user->name;
}
Re: Active Records VS Sql What Do You Think ?? by Seun(m): 10:20am On Sep 11, 2008
SQL is much better for data management. You can express almost any query in one line with SQL.
Re: Active Records VS Sql What Do You Think ?? by mambenanje(m): 8:24pm On Sep 11, 2008
Seun me and you again on this topic cheesy
well I wonder why sql will be better for data management. Its just like saying procedural programming is better that Object oriented programming.
Active Records just wraps the database into an object, something computer programmers understand better. and now we might keep the database admin at the level of designing and maintaining the database tables and relations while developers handle everything in codes and they dont need to ask any sql from the database admin.
with traditional sql you always need the DBA in big projects to give you the sql for everything or create you stored procedures to call.
Infact Seun on this one I declare myself right cheesy

(1) (Reply)

Ready Made Adsense Website / Lets Preview My Site Together / Claim Your own Website with domain of your choice Now!

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 14
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.