SQL 인젝션을 피하기 위해이를 수행하는보다 적절한 방법이 있습니다.
$resource = Mage::getSingleton('core/resource');
$write = $resource->getConnection('core_write');
$table = $resource->getTableName('your/model');
당신은 만들 수 있습니다 :
$write->insert(
$table,
['column_1' => 1, 'column_2' => 2]
);
읽다:
$select = $write->select()
->from(['tbl' => $table], ['entity_id', 'company'])
->join(['tbl2' => $table2], 'tbl.entity_id = tbl2.product_id', ['stuff'])
->where('name LIKE ?', "%{$name}%")
->group('company');
$results = $write->fetchAll($select);
최신 정보:
$write->update(
$table,
['column_1' => 3, 'column_2' => 4],
['entity_id = ?' => 123]
);
지우다:
$write->delete(
$table,
['entity_id IN (?)' => [123, 456]]
);
여러 개 삽입 :
$rows = [
['col_1'=>'value1', 'col_2'=>'value2', 'col_3'=>'value3'],
['col_1'=>'value3', 'col_2'=>'value4', 'col_3'=>'value5'],
];
$write->insertMultiple($table, $rows);
복제시 업데이트 삽입 :
$data = [];
$data[] = [
'sku' => $sku,
'name' => $name
];
$write->insertOnDuplicate(
$table,
$data, // Could also be an array of rows like insertMultiple
['name'] // this is the fields that will be updated in case of duplication
);