private function _oGetMysql() { if (is_null($this->_oMysql)) { $this->_oMysql = Ko_Data_Mysql::OInstance(KO_DB_HOST, KO_DB_USER, KO_DB_PASS, KO_DB_NAME); } return $this->_oMysql; }
/** * @return Ko_Data_Mysql */ public function oConnectDB($no, $sTag = 'slave') { $sid = $this->_aTableList[$no]['sid']; if (empty($this->_aServerList[$sid][$sTag])) { $sTag = empty($this->_aServerList[$sid]['slave']) ? 'master' : 'slave'; } assert(!empty($this->_aServerList[$sid][$sTag])); return Ko_Data_Mysql::OInstance($this->_aServerList[$sid][$sTag][0]['host'] . ':' . $this->_aServerList[$sid][$sTag][0]['port'], $this->_aServerList[$sid][$sTag][0]['user'], $this->_aServerList[$sid][$sTag][0]['passwd'], $this->_aTableList[$no]['db_name']); }
/** * @return string */ public static function SEscapeWhere($aArgs) { $iArgNum = count($aArgs); assert($iArgNum && false === strpos($aArgs[0], '\'') && false === strpos($aArgs[0], '"')); $where = $aArgs[0]; $pos = 0; for ($i = 1; $i < $iArgNum; ++$i) { $pos = strpos($where, '?', $pos); if (false === $pos) { break; } if (is_array($aArgs[$i])) { $escapeArg = array_map(array('Ko_Data_Mysql', 'SEscape'), $aArgs[$i]); $sReplace = '"' . implode('", "', $escapeArg) . '"'; } else { $sReplace = '"' . Ko_Data_Mysql::SEscape($aArgs[$i]) . '"'; } $where = substr($where, 0, $pos) . $sReplace . substr($where, $pos + 1); $pos += strlen($sReplace); } return $where; }
/** * @return Ko_Data_Mysql */ public function oConnectDB($no, $sTag = 'slave') { return Ko_Data_Mysql::OInstance(KO_DB_HOST, KO_DB_USER, KO_DB_PASS, KO_DB_NAME); }
private function _sInsertMultiSql($sKind, $aData, $oOption) { assert(!empty($aData)); $keys = array_keys($aData[0]); assert(!empty($keys)); $fields = $keys; foreach ($fields as &$field) { $field = '`' === $field[0] ? $field : '`' . $field . '`'; } unset($field); if ($oOption->bIgnore()) { $sql = 'INSERT IGNORE '; } else { $sql = 'INSERT '; } $sql .= 'INTO ' . $sKind . ' (' . implode(', ', $fields) . ') VALUES '; $values = array(); foreach ($aData as $data) { $vs = array(); foreach ($keys as $key) { $vs[] = Ko_Data_Mysql::SEscape($data[$key]); } $values[] = '("' . implode('", "', $vs) . '")'; } $sql .= implode(', ', $values); return $sql; }
private function _sGetSetSql($aUpdate, $aChange) { assert(is_array($aUpdate)); assert(is_array($aChange)); $set = array(); foreach ($aUpdate as $k => $v) { $set[] = $k . ' = "' . Ko_Data_Mysql::SEscape($v) . '"'; } foreach ($aChange as $k => $v) { $abs = abs($v); $set[] = $k . ' = ' . $k . ' ' . ($v >= 0 ? '+' : '-') . ' ' . $abs; } return implode(', ', $set); }