2013-07-08 2 views
0

내 모델에서이 기능을 실행하려고하면 문제가 발생합니다. print 문이 인쇄됩니다. Child_Name = '테스트' 및 Parent_username = 'tester2'내가 명령 줄에서 실행Codeigniter가 삭제 쿼리를 실행하지 않습니다

은 (기록이 존재하고 삭제) 제대로 작동 WHERE

child_participants에서 삭제. 그러나 내 웹 응용 프로그램에서 시도 할 때 오류가 있지만 실제로 아무것도 삭제하지 않습니다. 컨트롤러와 모델에서 데이터를 수신하기 때문에 데이터를 올바르게 전달하고 있음을 알고 있습니다. 뭐라 구요? documentation에서

function remove_child($username, $participant_name) 
    { 
    $where = "`Child_Name`='$participant_name' and`Parent_username`='$username'"; 
    $this->db->where($where, null, false); 
    $this->db->delete($this->child_table); 
    echo $this->db->last_query(); 
    } 
+0

$ this-> db -> _ error_message();'- 오류를 확인하십시오. –

+0

주제에서 벗어나지 만, codeigniter의 쿼리 작성 코드를 활용하여 SQL 삽입 공격을 막아야합니다. – Matthew

+0

@AmalMurali 주어진 오류 출력이 없습니다. – Undermine2k

답변

4

:

변경해보십시오 :에

$where = "`Child_Name`='$participant_name' and`Parent_username`='$username'"; 

여러 기능들이 AND로 연결됩니다 호출을 사용하는 경우

$this->db->where('Child_Name', $participant_name); 
$this->db->where('Parent_username', $username); 

// translates to WHERE Child_Name='XXX' and Parent_username='XXX' 

희망이 도움이됩니다.

0

메서드 호출 위치를 두 개로 나누면 같은 결과가 나타 납니까? where 메서드를 사용하는 방법을 통해이 작업을 수행합니다.

$this->db->where('Child_Name',$participant_name); 
$this->db->where('Parent_username',$username); 
$this->db->delete($this->child_table); 

또한, 우리는 그 충돌이 일어날 수 있습니다 또는 트랜잭션이

$this->output->enable_profiler(TRUE); 

를 범하지 볼 수없는 코드의 다른 부분이 없는지 확인하기 위해 실행되는 모든 쿼리를 확인하기 위해 프로파일 러를 켭니다

또 다른 제안은 소프트 삭제 작업이므로 데이터가 실제로 사라지지 않고 로그 파일 재구성에 얼마나 의존해야하는지 최소화합니다. 또한 간단한 CRUD 작업을 더 빠르게 수행하기 위해 기본 모델의 아주 간단한 확장을 사용할 수 있습니다. 내가 추천 한 바에 따르면 https://github.com/jamierumbelow/codeigniter-base-model

0

사용자가 데이터베이스에서 삭제 권한이 있는지 확인하십시오. 그것은이처럼 코드 변경보다가있는 경우 :

function remove_child($username, $participant_name) 
{ 
    $this->db->trans_start(); 
    $this->db->where('Child_Name',$participant_name); 
    $this->db->where('Parent_username',$username); 
    $this->db->delete($this->child_table); 
    $this->db->trans_complete(); 
    return TRUE; 
} 

을 나는이 문제를 해결할 수 있기를 바랍니다.

관련 문제