/** * @return \Sooh\DB\Interfaces\All */ public static function getInstance($arrConf_or_Index = null, $modName = null) { if (is_array($arrConf_or_Index)) { $conf = $arrConf_or_Index; } else { $ini = sooh_ini::getInstance(); if ($arrConf_or_Index === null) { $conf = $ini->get('dbConf'); if (isset($conf['default'])) { $conf = $conf['default']; } elseif (is_array($conf)) { $conf = current($conf); } else { throw new \ErrorException('default dbConf not found'); } } else { $conf = $ini->get('dbConf.' . $arrConf_or_Index); } } if (!isset($conf['name']) || $modName !== null) { if (isset($conf['dbEnums'][$modName])) { $conf['name'] = $conf['dbEnums'][$modName]; } else { $conf['name'] = $conf['dbEnums']['default']; } } $id = self::idOfConnection($conf); if (empty(self::$_instances[$id])) { $type = $conf['type']; if (empty($type)) { $ttmp = $ini->get('dbConf'); if (is_array($ttmp)) { $ttmp = implode(',', array_keys($ttmp)); } else { $ttmp = 'EMPTY'; } $err = new \ErrorException('db-config missing:' . json_encode($arrConf_or_Index) . ' current:' . $ttmp); error_log($err->getMessage() . "\n" . $err->getTraceAsString()); throw $err; } $class = '\\Sooh\\DB\\Types\\' . ucfirst($type); // if (!class_exists($class, false)) // include __DIR__ . '/' . $class . '.php'; self::$_instances[$id] = new $class($conf); self::$_instances[$id]->dbConf = $conf; if (sooh_trace::needsWrite(__CLASS__)) { sooh_trace::str('create new connection[' . $id . '] of ' . json_encode($conf)); } } else { if (sooh_trace::needsWrite(__CLASS__)) { sooh_trace::str('exists connection[' . $id . '] of ' . json_encode($conf)); } } return self::$_instances[$id]; }
public function free() { $this->disconnect(); $n = sizeof($this->wheresCreated); if ($n > 1) { foreach ($this->wheresCreated as $i => $o) { if ($i) { $o->end(); } } if (sooh_trace::needsWrite(__CLASS__)) { sooh_trace::str(__CLASS__ . ':' . $n . ' Where(s) created but not end.better check you code'); } } else { if (sooh_trace::needsWrite(__CLASS__)) { sooh_trace::str(__CLASS__ . ':all cleared'); } } }