2011-12-22 11 views
6

लौटाता है मैं कोडनिर्देशक संस्करण 2.0.3 का उपयोग कर रहा हूं। मैं

$this->db->affected_rows 

यह हमेशा 1 भले ही कोई पंक्ति को अद्यतन किया गया था रिटर्न का उपयोग कर एक अद्यतन क्वेरी के बाद प्रभावित पंक्तियों की संख्या प्राप्त कोशिश कर रहा हूँ। मैंने

mysql_affected_rows() 

और यह एक क्वेरी विफलता के लिए -1 देता है और 0 अगर कोई रिकॉर्ड अपडेट नहीं किया गया था।

संपादित मेरी कोड

मैं सिर्फ

$country_id = $this->input->post('country_id'); 
$time=$this->input->post('time'); 

$insert_array = array(
    'country' => $this->input->post('name') 
); 
$this->db->update('country_master', $insert_array, array("country_id" => $country_id,"last_updated"=>$time)); 
$afftectedRows=$this->db->affected_rows(); 
+1

क्या आप अपना कोड दिखाना चाहते हैं? –

+0

जो $ इससे पहले उपयोग की जा रही क्वेरी पर निर्भर करता है-> डीबी-> प्रभावित_रो यदि आप अपना कोड दिखा सकते हैं तो समाधान साझा करना आसान होगा। –

+0

हम्म यह मेरे हिस्से से एक त्रुटि थी। अब ठीक काम कर रहा है – Nick

उत्तर

13

वास्तव में उपयोग कर रहा हूँ शामिल मेरी कोड इस

if (!$country_id) { 
    $this->db->insert('country_master', $insert_array); 
    $id = $this->db->insert_id(); 
} else { 
    $this->db->update('country_master', $insert_array, array("country_id" => $country_id, "last_updated" => $time)); 
} 
$afftectedRows = $this->db->affected_rows(); 

की तरह था और मैं

if (!$country_id) {     
    $this->db->insert('country_master', $insert_array); 
    $id = $this->db->insert_id(); 
} else { 
    $this->db->update('country_master', $insert_array, array("country_id" => $country_id, "last_updated" => $time)); 
    $afftectedRows = $this->db->affected_rows(); 
} 

करने के लिए इसे संशोधित और अब यह ठीक काम कर रहा है।

और उत्तर के लिए आपको बहुत बहुत धन्यवाद ..

+1

धन्यवाद, @ निक। एकाधिक पंक्तियों को डालने पर प्रभावित पंक्ति प्राप्त करने के लिए कोई तकनीक? –