\PhalApi_Model

Model Class

  • provides database interface based on "Table Data Entrance"
  • provides base operations base on primary key(eg. id), and should translate the CLOB filed ext_data
  • in order to support multi tables, implemetation sub-class should use related table name by config


Usage:

 class Model_User extends PhalApi_Model_NotORM {

     protected function getTableName($id) {
         return 'user';
     }
 }

 $model = new Model_User();

 // retrieve
 $rs = $model->get($userId);

 // insert
 $model->insert(array('name' => 'whatever', 'from' => 'somewhere'));

 // update
 $model->update(1, array('name' => 'dogstar huang'));

 // delete
 $model->delete(1);

Summary

Methods
Constants
get()
insert()
update()
delete()
No constants found
No protected methods found
N/A
No private methods found
N/A

Methods

get()

get(\long  $id, \string/array  $fields = '*') : array

Retrieve record by primary key

Parameters

\long $id

primary key

\string/array $fields

the fileds to be retrieved, such as: name,from in string, or: array('name', 'from') in array

Returns

array —

table record, or return false when not found

insert()

insert(array  $data, \long  $id = NULL) : \long

Insert new record

it seems bo be a little strange, but the foreign key $id is required if we want to save data into multi tables

Parameters

array $data

data to be inserted, including the filed ext_data

\long $id

foreign key

Returns

\long —

the id of new record

update()

update(\long  $id, array  $data) : \TRUE/FALSE

Update record by primary key

Parameters

\long $id

primary key

array $data

data to be updated, including the filed ext_data

Returns

\TRUE/FALSE

delete()

delete(\long  $id) : \TRUE/FALSE

Delete record by primary key

Parameters

\long $id

primary key

Returns

\TRUE/FALSE