dsql() のいずれかのメソッドを使用してクエリを作成することは可能ですか?
何かのようなもの:
$dq=$this->api->db->dsql()->execute('insert into table xx (field1,field2) values ('a','b')');
ありがとう
dsql() のいずれかのメソッドを使用してクエリを作成することは可能ですか?
何かのようなもの:
$dq=$this->api->db->dsql()->execute('insert into table xx (field1,field2) values ('a','b')');
ありがとう
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();
ローマ人はすでに挿入の例を示しました。このようなデータの配列を選択できます ( debug() はオプションであり、結果の 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)
->set('col1',$somevalue)
->debug()
->do_update();
レコードを削除する
$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();