Welcome Guest, Not a member yet? Register   Sign In
Active Records VS Typing out the Query String
#1

[eluser]Dregond Rahl[/eluser]
What method do you think is better? and what is the actual difference ?
#2

[eluser]Dam1an[/eluser]
The main idea behind active record is that you can easily change database type, so by changing the driver from MySQL to Oracle
Writing the SQL gives slightly better performance, as using AR it gets created on the fly, but from what I've seen there's not much in it

I personally prefer to write them using AR
#3

[eluser]Thorpe Obazee[/eluser]
[quote author="Dam1an" date="1244119278"]The main idea behind active record is that you can easily change database type[/quote]

I don't think that's correct. You could use straight sql query as long as it's 'acceptable' in the database gonna be used.
#4

[eluser]Dam1an[/eluser]
Not including DB specific functionality, there are some subtle differences in syntax (I've ran into those problems before but can't remember what they where exactly now)

Also, some people just hate writting SQL lol so AR is good for that
#5

[eluser]Thorpe Obazee[/eluser]
[quote author="Dam1an" date="1244119516"]Also, some people just hate writting SQL lol so AR is good for that[/quote]

I think 'lazy' would be the term Tongue
#6

[eluser]Phil Sturgeon[/eluser]
[quote author="bargainph" date="1244119413"]I don't think that's correct. You could use straight sql query as long as it's 'acceptable' in the database gonna be used.[/quote]

Actually Dam1an is spot on. AR takes out all of the little non-standard quirks that exist between various SQL implementations. A few examples:

MySQL wildcard: %
MSSQL wildcard *

MySQL limit: LIMIT 10, 0
MSSQL limit: LIMIT 0, 10

There are more but I haven't had my morning coffee.

AR also helps with things such as auto-escaping of field names for more standard SQL and lets you set table name prefixes. If I used 100% AR then at any time I could change table names from `tablename` to `site1_tablename`. Very handy when making downloadable apps for the masses, and something I will have to revisit for PyroCMS.
#7

[eluser]Thorpe Obazee[/eluser]
[quote author="Phil Sturgeon" date="1244120012"]

MySQL wildcard: %
MSSQL wildcard *

MySQL limit: LIMIT 10, 0
MSSQL limit: LIMIT 0, 10
[/quote]

Hmm... and I thought MSSQL uses * for wildcards. Never used it though.
#8

[eluser]Dam1an[/eluser]
@phil Thanks for backing me up Wink
@Bargainph Told you so Tongue

Although I didn't think of the table prefix one, cause I've never used 'em before
#9

[eluser]Thorpe Obazee[/eluser]
[quote author="Dam1an" date="1244120903"]
@Bargainph Told you so Tongue
[/quote]

lol.

Anyway, I use the AR cause it's faster when developing and for me it's much more flexible. The table prefix thing can be handled by retrieving $this->db->dbprefix if you really don't plan to use AR.
#10

[eluser]mddd[/eluser]
Writing SQL directly or using the AR functionality is like using only PHP or using a framework (like CI):
if you are only doing one task one time, writing directly is probably quicker. But as soon as requirements change, you want to re-use stuff, you have to change it, then the advantages of having a structure in place will kick in.




Theme © iAndrew 2016 - Forum software by © MyBB