Ignore:
Timestamp:
2009/06/12 14:45:35 (15 years ago)
Author:
Seasoft
Message:

・SC_DbConn#getRow の改訂
・SC_Query#getRow の改訂
・SC_Query#update の改訂
・ソース整形

Location:
branches/comu-ver2/data/class
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/comu-ver2/data/class/SC_DbConn.php

    r17595 r18098  
    2727$objDbConn = ""; 
    2828 
    29 class SC_DbConn{ 
     29class SC_DbConn { 
    3030 
    3131    var $conn; 
     
    8686 
    8787        if ($this->conn->isError($result) && !$ignore_err){ 
    88             $this->send_err_mail ($result, $n); 
     88            $this->send_err_mail($result, $n); 
    8989        } 
    9090 
     
    105105        } 
    106106        if ($this->conn->isError($result)){ 
    107             $this->send_err_mail ($result ,$n); 
    108         } 
    109         $this->result = $result; 
    110  
    111         return $this->result; 
    112     } 
    113  
    114     function getRow($n, $arr = ""){ 
    115  
    116         // mysqlの場合にはビュー表を変換する 
    117         if (DB_TYPE == "mysql") $n = $this->dbFactory->sfChangeMySQL($n); 
    118  
    119         if ( $arr ) { 
    120             $result = $this->conn->getRow($n, $arr); 
    121         } else { 
    122             $result = $this->conn->getRow($n); 
    123         } 
    124         if ($this->conn->isError($result)){ 
    125             $this->send_err_mail ($result ,$n); 
     107            $this->send_err_mail($result ,$n); 
     108        } 
     109        $this->result = $result; 
     110 
     111        return $this->result; 
     112    } 
     113     
     114    /** 
     115     * クエリを実行し、最初の行を返す 
     116     * 
     117     * @param string $sql SQL クエリ 
     118     * @param array $arrVal プリペアドステートメントの実行時に使用される配列。配列の要素数は、クエリ内のプレースホルダの数と同じでなければなりません。  
     119     * @param integer $fetchmode 使用するフェッチモード。デフォルトは DB_FETCHMODE_ASSOC。 
     120     * @return array データを含む1次元配列。失敗した場合に DB_Error オブジェクトを返します。 
     121     */ 
     122    function getRow($sql, $arrVal = array(), $fetchmode = DB_FETCHMODE_ASSOC) { 
     123         
     124        // mysqlの場合にはビュー表を変換する 
     125        if (DB_TYPE == "mysql") $sql = $this->dbFactory->sfChangeMySQL($sql); 
     126         
     127        $result = $this->conn->getRow($sql, $arrVal ,$fetchmode); 
     128         
     129        if ($this->conn->isError($result)){ 
     130            $this->send_err_mail($result ,$sql); 
    126131        } 
    127132        $this->result = $result; 
     
    168173 
    169174        if ($this->conn->isError($result)){ 
    170             $this->send_err_mail ($result, $n); 
     175            $this->send_err_mail($result, $n); 
    171176        } 
    172177        $this->result = $result; 
     
    184189 
    185190        if ($this->conn->isError($result)){ 
    186             $this->send_err_mail ($result, $n); 
     191            $this->send_err_mail($result, $n); 
    187192        } 
    188193        $this->result = $result; 
  • branches/comu-ver2/data/class/SC_Query.php

    r18091 r18098  
    277277     * @param array $sqlval array('カラム名' => '値',...)の連想配列 
    278278     * @param string $where WHERE句 
    279      * @param array $arradd $addcol用のプレースホルダ配列 
    280      * @param string $addcol 追加カラム 
     279     * @param array $arrValIn $where,$arrRawSql用のプレースホルダ配列 
     280     * @param string $arrRawSql 追加カラム 
    281281     * @return 
    282282     */ 
    283     function update($table, $sqlval, $where = "", $arradd = "", $addcol = "") { 
    284         $strcol = ''; 
     283    function update($table, $sqlval, $where = "", $arrValIn = array(), $arrRawSql = array()) { 
     284        $arrCol = array(); 
     285        $arrVal = array(); 
    285286        $find = false; 
    286287        foreach ($sqlval as $key => $val) { 
    287             if(eregi("^Now\(\)$", $val)) { 
    288                 $strcol .= $key . '= Now(),'; 
     288            if (eregi("^Now\(\)$", $val)) { 
     289                $arrCol[] = $key . '= Now()'; 
    289290            } else { 
    290                 $strcol .= $key . '= ?,'; 
    291                 $arrval[] = $val; 
     291                $arrCol[] = $key . '= ?'; 
     292                $arrVal[] = $val; 
    292293            } 
    293294            $find = true; 
    294295        } 
    295         if(!$find) { 
     296 
     297        if ($arrRawSql != "") { 
     298            foreach($arrRawSql as $key => $val) { 
     299                $arrCol[] = "$key = $val"; 
     300            } 
     301        } 
     302 
     303        if (empty($arrCol)) { 
    296304            return false; 
    297305        } 
    298306 
    299         if($addcol != "") { 
    300             foreach($addcol as $key => $val) { 
    301                 $strcol .= "$key = $val,"; 
    302             } 
    303         } 
    304  
    305307        // 文末の","を削除 
    306         $strcol = ereg_replace(",$","",$strcol); 
    307  
    308         if($where != "") { 
    309             $sqlup = "UPDATE $table SET $strcol WHERE $where"; 
    310         } else { 
    311             $sqlup = "UPDATE $table SET $strcol"; 
    312         } 
    313  
    314         if(is_array($arradd)) { 
     308        $strcol = implode(', ', $arrCol); 
     309 
     310        if (is_array($arrValIn)) { // 旧版との互換用 
    315311            // プレースホルダー用に配列を追加 
    316             foreach($arradd as $val) { 
    317                 $arrval[] = $val; 
    318             } 
     312            $arrVal = array_merge($arrVal, $arrValIn); 
     313        } 
     314 
     315        $sqlup = "UPDATE $table SET $strcol"; 
     316        if (strlen($where) >= 1) { 
     317            $sqlup .= " WHERE $where"; 
    319318        } 
    320319 
    321320        // UPDATE文の実行 
    322         $ret = $this->conn->query($sqlup, $arrval); 
    323         return $ret; 
     321        return $this->conn->query($sqlup, $arrVal); 
    324322    } 
    325323 
     
    367365    } 
    368366 
    369     // 一行を取得 
    370     function getrow($table, $col, $where = "", $arrval = array()) { 
    371         if(strlen($where) <= 0) { 
    372             $sqlse = "SELECT $col FROM $table"; 
    373         } else { 
    374             $sqlse = "SELECT $col FROM $table WHERE $where"; 
     367    /** 
     368     * 一行をカラム名をキーとした連想配列として取得 
     369     * 
     370     * @param string $table テーブル名 
     371     * @param string $col カラム名 
     372     * @param string $where WHERE句 
     373     * @param array $arrVal プレースホルダ配列 
     374     * @param integer $fetchmode 使用するフェッチモード。デフォルトは DB_FETCHMODE_ASSOC。 
     375     * @return array array('カラム名' => '値', ...)の連想配列 
     376     */ 
     377    function getRow($table, $col, $where = "", $arrVal = array(), $fetchmode = DB_FETCHMODE_ASSOC) { 
     378        $sqlse = "SELECT $col FROM $table"; 
     379         
     380        if (strlen($where) >= 1) { 
     381            $sqlse .= " WHERE $where"; 
    375382        } 
    376383        // SQL文の実行 
    377         $ret = $this->conn->getRow($sqlse, $arrval); 
    378  
    379         return $ret; 
     384        return $this->conn->getRow($sqlse, $arrVal ,$fetchmode); 
    380385    } 
    381386 
  • branches/comu-ver2/data/class/helper/SC_Helper_Mobile.php

    r17676 r18098  
    390390        $objQuery = new SC_Query; 
    391391 
    392         $arrRow = $objQuery->getrow('dtb_mobile_kara_mail', 'session_id, next_url, email', 
    393                                     'token = ? AND email IS NOT NULL AND receive_date >= ?', 
    394                                     array($token, date('Y-m-d H:i:s', time() - MOBILE_SESSION_LIFETIME))); 
     392        $arrRow = $objQuery->getRow( 
     393             'dtb_mobile_kara_mail' 
     394            ,'session_id, next_url, email' 
     395            ,'token = ? AND email IS NOT NULL AND receive_date >= ?' 
     396            ,array($token, date('Y-m-d H:i:s', time() - MOBILE_SESSION_LIFETIME)) 
     397            ,DB_FETCHMODE_ORDERED 
     398        ); 
     399         
    395400        if (!isset($arrRow)) { 
    396401            return false; 
  • branches/comu-ver2/data/class/pages/magazine/LC_Page_Magazine_Confirm.php

    r17590 r18098  
    252252 
    253253        // NULLも購読とみなす 
    254         if (count($mailResult) == 0 or ($mailResult[1] != null and $mailResult[1] != 2 )) { 
     254        if (count($mailResult) == 0 or ($mailResult['mailmaga_flg'] != null and $mailResult['mailmaga_flg'] != 2 )) { 
    255255            return false; 
    256256        } else { 
Note: See TracChangeset for help on using the changeset viewer.