Article View: pl.comp.lang.php
Article #231090Re: MVC: zapytanie SQL z kontrolera
From: jivanmukta
Date: Tue, 28 Jul 2015 12:28
Date: Tue, 28 Jul 2015 12:28
26 lines
2576 bytes
2576 bytes
Przyjąłem zasadę, że w przypadku prostych, pojedynczych instrukcji SQL, używam kodów błędów (najczęściej TRUE/FALSE), np.:
public function acceptAgencies(array $agencies, $day) {
$this->db->query('UPDATE agencies SET date_entered = ' . $this->ci->common->convertToDb($day) . ' ' .
' WHERE agency_id IN (' . implode(', ', $agencies) . ')');
return $this->db->affected_rows() == count($agencies);
}
natomiast w przypadku złożonych operacji objętych transakcjami, używam wyjątków:
// wczytaj listę agencji:
public function import($fileName, array $estateTypes) {
$this->db->trans_start();
try {
// wczytaj listę:
$this->importFromFile(IMPORT_DIR . DIRECTORY_SEPARATOR . $fileName);
$this->insertIntoDb($estateTypes);
} catch (Exception $e) {
$this->db->trans_rollback();
$this->common->error($e->getMessage());
}
$this->db->trans_complete();
return $this->db->trans_status();
}
Czy to ma sens?
Technical Details
Message-ID:
<a72748a9-2485-40bb-854d-55955a769c80@googlegroups.com>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed.pionier.net.pl!news.glorb.com!pg9no4669586igb.0!news-out.google.com!4ni82428qgh.1!nntp.google.com!z61no3778560qge.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mailReferences:
<40546498-26c6-4e09-a62f-815df4bdc3f8@googlegroups.com> <18ib0oawqi49n$.zkxevcy1a7jc.dlg@40tude.net> <db28497e-bddd-44e5-9575-5cf1a3fe5c41@googlegroups.com> <1mg1pouopguup.jcxkalwncm2x$.dlg@40tude.net> <41f4e3a9-f1eb-4566-b59d-070e8adb52c6@googlegroups.com> <f1w4cvuwawti$.in9jfueie26q$.dlg@40tude.net> <140d567e-85f8-4073-a5ea-6bcfc4362b09@googlegroups.com> <mbampg1n4760$.1rvzkky97kjm7.dlg@40tude.net>Show Full Headers
Complete Article Headers
X-Received: by 10.66.90.163 with SMTP id bx3mr35069431pab.28.1438086516585; Tue, 28 Jul 2015 05:28:36 -0700 (PDT) X-Received: by 10.140.91.182 with SMTP id z51mr502122qgd.5.1438086516334; Tue, 28 Jul 2015 05:28:36 -0700 (PDT) Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed.pionier.net.pl!news.glorb.com!pg9no4669586igb.0!news-out.google.com!4ni82428qgh.1!nntp.google.com!z61no3778560qge.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: pl.comp.lang.php Date: Tue, 28 Jul 2015 05:28:36 -0700 (PDT) In-Reply-To: <mbampg1n4760$.1rvzkky97kjm7.dlg@40tude.net> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=178.43.27.219; posting-account=Fd8BNwoAAACl8PCi6-fI0bkHGOgt6LMa NNTP-Posting-Host: 178.43.27.219 References: <40546498-26c6-4e09-a62f-815df4bdc3f8@googlegroups.com> <18ib0oawqi49n$.zkxevcy1a7jc.dlg@40tude.net> <db28497e-bddd-44e5-9575-5cf1a3fe5c41@googlegroups.com> <1mg1pouopguup.jcxkalwncm2x$.dlg@40tude.net> <41f4e3a9-f1eb-4566-b59d-070e8adb52c6@googlegroups.com> <f1w4cvuwawti$.in9jfueie26q$.dlg@40tude.net> <140d567e-85f8-4073-a5ea-6bcfc4362b09@googlegroups.com> <mbampg1n4760$.1rvzkky97kjm7.dlg@40tude.net> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <a72748a9-2485-40bb-854d-55955a769c80@googlegroups.com> Subject: Re: MVC: zapytanie SQL z kontrolera From: jivanmukta@poczta.onet.pl Injection-Date: Tue, 28 Jul 2015 12:28:36 +0000 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit