Welcome Guest, Not a member yet? Register   Sign In
Problems with Active Record
#1

[eluser]Snoob[/eluser]
Quote:$this->db->select('user_name')->from('user')->where('user_name',$user);
$query = $this->db->get();
This is the script I've used. What is my wrong?
:-S
#2

[eluser]jedd[/eluser]
Hi Snoob and welcome to the forums.

You might need to be a bit more detailed in what is going wrong, and what you expect to happen.

The two things that look wrong to me there are - chaining is only available in PHP5, and you appear to be grabbing a piece of data from the database that you already have.
#3

[eluser]yudahebat[/eluser]
Code:
$this->db->select(‘user_name’);
$this->db->where(‘user_name’,$user);
$query = $this->db->get('your_database_name');

maybe like this....
#4

[eluser]boony[/eluser]
[quote author="Snoob" date="1239121029"]
Quote:$this->db->select('user_name')->from('user')->where('user_name',$user);
$query = $this->db->get();
This is the script I've used. What is my wrong?
:-S[/quote]

Or nothing wrong with the good 'ol $this->db->query('SELECT user_name FROM user WHERE user_name=$user')
Quick and simple as well....
#5

[eluser]xwero[/eluser]
or with escaping and adding quotes
Code:
$this->db->query(‘SELECT user_name FROM user WHERE user_name=?’,array($user));
#6

[eluser]n0xie[/eluser]
Euhm, what's the point in using Active Record if you're going to write your own queries...?

The whole point of Active Record is to abstract away the SQL statements and treat a database as 'just another data object'. In an ideal world it shouldn't matter what implementation is used to store the data, be it database, sqlfile, csv, xml or whatever other format you can think up. The Active Record class should determine what is needed to supply the needed data. Hence it doesn't matter (much) what type of database you use (postgresql, mysql, mssql, oracle etc) since the Active Record class will construct the SQL statements according to the database driver it uses.

If you're going to write your own SQL statements, you might as well NOT use Active Record since it comes at a slight performance cost.
#7

[eluser]xwero[/eluser]
the query method isn't a part of the AR class, it's part of the DB class. There might be a slight performance it not using the php native methods but i think the simplified syntax and other benefits are worth it.

The biggest performanceloss is while using the AR sql statement builder methods.
#8

[eluser]n0xie[/eluser]
[quote author="xwero" date="1239197247"]the query method isn't a part of the AR class, it's part of the DB class. There might be a slight performance it not using the php native methods but i think the simplified syntax and other benefits are worth it.

The biggest performanceloss is while using the AR sql statement builder methods.[/quote]
That was my whole point: you're not using the AR class. The OP was asking for help using the AR class, and you're basically saying: 'just do it yourself'...




Theme © iAndrew 2016 - Forum software by © MyBB