Welcome Guest, Not a member yet? Register   Sign In
A newbie on php and CI
#1

[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
#2

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

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

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

[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()
#5

[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 ...
#6

[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 ?
#7

[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.
#8

[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 ?
#9

[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());
#10

[eluser]Gweg[/eluser]
It's ok now. Thx for help...




Theme © iAndrew 2016 - Forum software by © MyBB