繁体   English   中英

我的CodeIgniter SQL简单查询出了什么问题?

[英]What's wrong with my CodeIgniter SQL simple Query?

我只是对一个让我疯狂的查询有一点疑问。 我正在使用CI,这是我第一次使用这个伟大的框架

1-好的,所以我有一个插入查询工作得相当好:

$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);  

我不明白为什么它总是插入数据两次......!

2-然后我得到了第二个问题:我只想找到一个有相关facebook_id的用户,所以我试试:

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

echo '<pre>';
print_r($resultat);
echo '</pre>';  

我也尝试过:

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

但在这两种情况下,我得到的唯一数组是:

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] =>
)

所以[result_id]没问题,但是没有数据(据说它应该在[row_data]中打印?)当我只是尝试使用mysql时,我得到了正确的成员。 但是对于CI,它似乎不起作用。

3-此外,当我尝试这样的事情时:

echo $resultat['nom'];  

它不被视为一个数组..

所以..是的,我真的不明白..如果有人能够点燃我?

不要忘记最后使用result()方法,否则你只获得资源。 像这样:

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

这回答了第二个和第三个问题,至于第一个我需要看看你怎么称呼它 - 代码看起来没问题,而我的赌注是你可能以某种方式调用它两次。

为2和3

这将与你合作

$this->db->select('nom');
$this->db->from('membre');
$query = $this->db->get_where('facebook_id',$fb_data['uid']);
$row= $result->row();

echo '<pre>';
echo'$row->uid'; // that will prent user id , you can change to what ever you want ex.  i want tp prent username it will be like this $row->username it should be same as database column 
echo '</pre>';  

1 - 你确定你没有两次调用insert(...)吗? 也许您可以使用$this->db->last_query()来查看结果查询。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM