2011-09-21 4 views

답변

3

DSQL는 이제 별도의 라이브러리로 리팩토링된다 https://git.io/dsql

$this->api->db->dsql()->table('table')->set('field1','a')->set('field2','b')->do_insert(); 

는 당연히 당신은 또한 사용할 수 있습니다

$this->api->db->dsql()->table('table')->set($associative_array)->do_insert(); 
+0

감사합니다. ocharles가 맞습니다. 내 실수. –

+0

DSQL은 이제 독립 실행 형 라이브러리입니다. https://github.com/atk4/dsql – romaninsh

1

로마인은 이미 삽화의 예를 보여주었습니다. 이 같은 데이터 (디버그를 (주) 선택 사항이며 의지 출력 페이지 상단에서의 결과 SQL 문을) 뭔가를

을 수행하는 결과 집합을 통해

$db=$this->api->db->dsql()->table('table1 x') 
      ->field('x.col1') 
     ->field('sum(x.col2) col2') 
    //   ->debug() 
     ->join('table2 y','x.id=y.some_id') 
     ->where('x.col3','Y') 
     ->where('x.col4',$this->auth->api->get('id')) 
     ->group('x.col2') 
        ->order('x.col1') 
     ->do_getAll(); 

다음 루프의 배열을 선택할 수 있습니다

foreach ($db as $row) { 
     if (is_array($row)) { 
     //do something here with row['col1'], row['col2']    
     } 
    } 

그냥 당신이 기록

를 업데이트 할 수 있습니다

$db=$this->api->db->dsql()->table('table1 x') 
      ->field('x.col1') 
     ->where('x.col2,'constant') 
     ->do_getOne(); 

하나의 값을 선택개

및 삭제 기록

  $this->api->db->dsql()->table('table1 x') 
      ->where('id',$somevariable) 
      ->do_delete(); 

수, 그것은 당신의 데이터를 유지하기 위해 다음과 같은 모델을 사용하는 것이 가장 좋습니다하지만 ATK4에 대한 좋은 점은 당신이, 당신이 실행할 수있는 필요가 그래서 만약 그것이 방해가 나던입니다 귀하의 페이지에서 SQL 어디서나 간단한 결과를 얻을 수 있습니다.

 $s=$p->add('Model_Story')->loadData($story); 
     $s->set('points', $value); 
     $s->update(); 
관련 문제