echo "<h3>adodb_backtrace:</h3>\n"; $e = adodb_backtrace($e->gettrace()); } $rs = $db->Execute("select distinct id, firstname,lastname from adoxyz order by id"); echo "Result=\n", $rs, "</p>"; echo "<h3>Active Record</h3>"; include_once "../adodb-active-record.inc.php"; ADOdb_Active_Record::SetDatabaseAdapter($db); try { class City extends ADOdb_Active_Record { } $a = new City(); } catch (exception $e) { echo $e->getMessage(); } try { $a = new City(); echo "<p>Successfully created City()<br>"; #var_dump($a->GetPrimaryKeys()); $a->city = 'Kuala Lumpur'; $a->Save(); $a->Update(); #$a->SetPrimaryKeys(array('city')); $a->country = "M'sia"; $a->save(); $a->Delete(); } catch (exception $e) { echo $e->getMessage(); } //include_once("test-active-record.php");
/** * API Method inserts a new City record and render response as JSON */ public function Create() { try { $json = json_decode(RequestUtil::GetBody()); if (!$json) { throw new Exception('The request body does not contain valid JSON'); } $city = new City($this->Phreezer); // TODO: any fields that should not be inserted by the user should be commented out // this is an auto-increment. uncomment if updating is allowed // $city->Idcity = $this->SafeGetVal($json, 'idcity'); $city->State = $this->SafeGetVal($json, 'state'); $city->Institution = $this->SafeGetVal($json, 'institution'); $city->Citypublic = $this->SafeGetVal($json, 'citypublic'); $city->City = $this->SafeGetVal($json, 'city'); $city->Citycode = $this->SafeGetVal($json, 'citycode'); $city->Validate(); $errors = $city->GetValidationErrors(); if (count($errors) > 0) { $this->RenderErrorJSON('Please check the form for errors', $errors); } else { $city->Save(); $this->RenderJSON($city, $this->JSONPCallback(), true, $this->SimpleObjectParams()); } } catch (Exception $ex) { $this->RenderExceptionJSON($ex); } }