/** * Returns an instance of a Pfw_Db_Adapter * * @param $route the name of the route * @param $reuse * @return Pfw_Db_Adapter */ public static function factory($route = null, $reuse = true) { if (null === $route) { if (!isset(self::$default_router)) { Pfw_Loader::loadClass('Pfw_Db_Router_Standard'); self::$default_router = new Pfw_Db_Router_Standard(self::DEFAULT_ROUTE_NAME); } $route = self::$default_router->getWriteRoute(); } if (true == $reuse) { $reuse_key = self::_genCnxKey($route); if (isset(self::$_connections[$reuse_key])) { self::$_connections[$reuse_key]->isSharedCnx(true); return self::$_connections[$reuse_key]; } } $adapter_key = strtolower($route['adapter']); if (!isset(self::$_supported_adapters[$adapter_key])) { Pfw_Loader::loadClass('Pfw_Exception_Db'); throw new Pfw_Exception_Db("Adapter type {$route['adapter']} is unsupported"); } $class = 'Pfw_Db_Adapter_' . $route['adapter']; Pfw_Loader::loadClass($class); $instance = new $class($route); if (true == $reuse) { self::$_connections[$reuse_key] = $instance; self::$_connections[$reuse_key]->isSharedCnx(true); } else { $instance->isSharedCnx(false); } return $instance; }
public function open($save_path, $session_name) { $this->config = Pfw_Config::get('session'); $db_route_name = $this->config['handler']['db_route_name']; $db_router = new Pfw_Db_Router_Standard($db_route_name); $db_route = $db_router->getWriteRoute(); $this->db = Pfw_Db::factory($db_route, true); $this->sessions = array(); $this->db_table = isset($this->config['handler']['db_table']) ? $this->config['handler']['db_table'] : self::DEFAULT_DB_TABLE; return true; }
protected static function _do($statements, $force, $route_name) { $router = new Pfw_Db_Router_Standard($route_name); $routes = $router->getAllWriteRoutes(); foreach ($routes as $route) { $db = Pfw_Db::factory($route, false); foreach ($statements as $statement) { echo "running sql: \"{$statement}\"\n"; if (false == self::$_dry_run) { if ($force) { try { $out = $db->query($statement); } catch (Exception $e) { } } else { $out = $db->query($statement); } } } } }
public function saveProjectData($data, $options) { // Create taxon map one time Pfw_Loader::loadModel('Taxon'); $field_names = $options['field_names']; $pid = $options['pid']; $num_cols = count($field_names); $taxons = Taxon::Q()->exec(); $taxon = array(); // strtolower $fields = array_filter($field_names, "strtolower"); $depth_index = array_search('depth', $fields); error_log("fields columns are " . print_r($fields, true)); foreach ($taxons as $t) { $taxon[$t->name] = $t->type; } error_log("taxons are " . print_r($taxon, true)); // foreach row in data array process individual columns foreach ($data as $d) { $sql = null; $depth = $d[$depth_index]; for ($i = 0; $i < $num_cols; $i++) { if ($i == $depth_index) { continue; } //error_log(print_r($d,true)); $tname = strtolower($fields[$i]); $null_val = "'NULL'"; $taxon_type = empty($taxon[$tname]) ? $null_val : $taxon[$tname]; $taxon_value = empty($d[$i]) ? $null_val : $d[$i]; error_log("TAXON VALUE IS {$taxon_value}"); $sql = "INSERT INTO project_data (project_id,depth,taxon_type, taxon_value) VALUES({$pid},{$depth},{$taxon_type},{$taxon_value});"; error_log($sql); Pfw_Db::factory()->query($sql); } // now fire the insert sql } }
public function clearProjectData($pid) { if (empty($pid)) { return false; } $sql = "DELETE FROM project_data where project_id={$pid}"; Pfw_Db::factory()->query($sql); return true; }
public function getCnxForTxn() { return Pfw_Db::factoryForTxn(); }
/** * Gets the db adapter instance that this model is currently using. * * @param bool $reuse use an existing link * @return Pfw_Db_Adapter */ public function _getDb($reuse = true) { if (true == $reuse) { if (!isset($this->_db)) { $this->_db = Pfw_Db::factory(null, $reuse); } return $this->_db; } return Pfw_Db::factory(null, $reuse); }
public function dropTables() { Pfw_Db::factory()->query("DROP TABLE IF EXISTS things"); Pfw_Db::factory()->query("DROP TABLE IF EXISTS foos"); Pfw_Db::factory()->query("DROP TABLE IF EXISTS bars"); Pfw_Db::factory()->query("DROP TABLE IF EXISTS users"); Pfw_Db::factory()->query("DROP TABLE IF EXISTS members"); Pfw_Db::factory()->query("DROP TABLE IF EXISTS membership"); Pfw_Db::factory()->query("DROP TABLE IF EXISTS groups"); }
public function getCnx() { return Pfw_Db::factory(); }
function activate() { $sql = sprintf('UPDATE users SET is_active = 1 where id = %s', $this->id); Pfw_Db::factory()->query($sql); }