Why does CodeIgniter's insert() create 2 rows and why does my SELECT query result object show no rows and how to access a column value from a row?
13:46 20 Nov 2011

I just have a little question about a query making me crazy. I'm working with CI, and tis is the first time i'm using this great framework

1— Okay so I have an insert query working rather well :

$data = array(

 'nom' => $nom,
 'prenom' => $prenom,
 'login' => $prenom.' '.$nom,
 'password' => 'facebook',
 'email' => $fb_data['me']['email'],
 'mobile' => "00",
 'etat' => "1",
 'role' => "1",
 'ville' => 'ville actuelle',
 'facebook_id' => $fb_data['uid'],     
);

$this->db->insert('membre', $data);  

And I don’t understand why it always insert the data twice ... !

2— Then I got a second question : I just wanna found a user with the related facebook_id so i try that :

$this->db->select('nom');
$this->db->from('membre');
$this->db->where('facebook_id',$fb_data['uid']);
$resultat=$this->db->get();

echo '
';
print_r($resultat);
echo '
';

I’ve also tried :

$resultat2 = $this->db->get_where('membre',array('facebook_id' => $fb_data['uid']));
echo '
';
print_r($resultat2);
echo '
';

But in both case, the only array I got is :

CI_DB_mysql_result Object
(
  [conn_id] => Resource id #36
  [result_id] => Resource id #61
  [result_array] => Array
      (
      )

  [result_object] => Array
      (
      )

  [custom_result_object] => Array
      (
      )

  [current_row] => 0
  [num_rows] => 1
  [row_data] =>
)

So the [result_id] is okay, but there is no data (as far as it is supposed to be printed in [row_data] ?) When I simply try on mysql i got the right result with the right member. But with CI, it doesn’t seems to work.

3— Furthermore, when i Try something like that :

echo $resultat['nom'];  

it isn’t considered as an array ..

So .. yeah, I don’t really understand .. If anyone could enlight me ?

php mysql codeigniter query-builder