function updateSchemaAction() { try { $apiID = $this->_request->getParam(api); $api = new Api_Model_Profile(); $api->find($apiID); $sql = $api->sql; $conn = App_Env::getDb(); $dbh = $conn->getConnection(); print_r($dbh); $sth = $dbh->prepare($sql); $sth->execute(); $colcount = $sth->columnCount(); $typelist = array("LONG" => 'int', "VAR_STRING" => 'string', 'DATETIME' => 'datetime', 'BLOB' => 'text', 'DATE' => 'date'); $inputlist = array("LONG" => 'text', "VAR_STRING" => 'text', 'DATETIME' => 'text', 'BLOB' => 'textarea', 'DATE' => 'datepicker'); for ($i = 0; $i < $colcount; $i++) { $coll = $sth->getColumnMeta($i); $collName = $coll['name']; $propName = strtolower($collName); $propName = str_replace("_", " ", $propName); $propName = ucwords($propName); $propName = str_replace(" ", "", $propName); $propName = lcfirst($propName); $type = $coll['native_type']; if ($type == '') { $type = 'text'; } $schema = new Api_Model_Service_Schema(); $result = $schema->fetchRow($schema->select()->where('attribute_name=?', $propName)->where('api_id=?', $apiID)); if (trim($result->id) == '') { $schema->setApiId($apiID)->setAttributeName($propName)->setColumnName($collName)->setType($typelist)->save(); } } $this->_helper->redirector('index', null, null, array('api' => $apiID, 'info' => 101)); } catch (Exception $e) { $this->_helper->redirector('index', null, null, array('api' => $apiID, 'info' => $e->getMessage())); echo "ERROR" . $e->getMessage(); } }
/** * get Singleton Api_Model_Profile * * @return Api_Model_Profile */ public static function getObjectByID($id) { $obj = new Api_Model_Profile(); $obj->find($id); return $obj; }