CodeIgniter Forums

Full Version: A newbie on php and CI
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2

El Forum

[eluser]Gweg[/eluser]
Sorry for my english and my level in php, i'm a newbie...

So in a model i want to access one of my table with this :

Quote:$query = $this->db->select('nam_first_name')->from('NAM')->where('nam_id', $var1);

I want to get the value of my nam_first_name. So i try this :

Quote: $row = $query->row();

And BING

Quote:Fatal error: Call to undefined method CI_DB_mysql_driver::row() in

El Forum

[eluser]sophistry[/eluser]
welcome to CI....

did you open the config.php file and enter your database information?

El Forum

[eluser]Gweg[/eluser]
Yes. I success to access my DB. I success in insert row in my table.

El Forum

[eluser]sophistry[/eluser]
oh yes, right, i just re-read your code sample...

are you running a query(), get() or a get_where() method before the row() method? you need to "execute" the select query by using get() get_where() or query()

El Forum

[eluser]sandwormusmc[/eluser]
Have you tried running it with $result=$this->db->query(<SQL STATEMENT>) just by itself, then doing print_r($result)? It's outside of the framework functions, but if that doesn't work then you probably have a deeper problem ...

El Forum

[eluser]Gweg[/eluser]
[quote author="sophistry" date="1202786984"]oh yes, right, i just re-read your code sample...

are you running a query(), get() or a get_where() method before the row() method? you need to "execute" the select query by using get() get_where() or query()[/quote]

No, the two lines were like this :

Quote:$query = $this->db->select('nam_first_name')->from('NAM')->where('nam_id', $var1);
echo $query->nam_first_name;

I think that the first one do a select query, and $query is an object with the value... am i wrong ?

I'm not fluent with php, so how do you call a query method ?

El Forum

[eluser]sophistry[/eluser]
no, select() simply builds the query string inside the Active Record Class. you have to do query() to get it to execute the query string.

try sandwormusmc's suggestion above.

El Forum

[eluser]Gweg[/eluser]
i code this :

Quote:$result=$this->db->query('Select nam_first_name from NAM where nam_id = ".$var1."');
print_r($result);


Result :


Quote:CI_DB_mysql_result Object ( [conn_id] => Resource id #27 [result_id] => Resource id #31 [result_array] => Array ( ) [result_object] => Array ( ) [current_row] => 0 [num_rows] => 0 [row_data] => )

I think i had to get my dictionnary of php, because i don't understand the result.

Is that mean, that i have a result ?


I try without the "$var1" :

Quote:$result=$this->db->query('Select nam_first_name from NAM where nam_id = 1');
print_r($result);

Result :

Quote:CI_DB_mysql_result Object ( [conn_id] => Resource id #27 [result_id] => Resource id #31 [result_array] => Array ( ) [result_object] => Array ( ) [current_row] => 0 [num_rows] => 1 [row_data] => )

It seems that i have a result.

How i can take it in a variable ?

El Forum

[eluser]sophistry[/eluser]
ok, you're almost there.

just add this... (you have to call the result() method that is "in" the CI_DB_mysql_result Object.)

Code:
print_r($result->result());

El Forum

[eluser]Gweg[/eluser]
It's ok now. Thx for help...
Pages: 1 2