Skip to content
zuowenjian@ayb edited this page Jun 26, 2016 · 3 revisions

设定数据库访问

_run.yaml

DB_HOST             : "mysql.server"
DB_NAME             : "project_${USER}"
DB_USER             : "you"
DB_PWD              : "password"

2、实体编写

  class SPU extends XEntity
  {
  
      static public function bizCreate($key,$name)
      {   
          $obj = XEntity::createIns(__class__) ;
          $obj->ukey = $key ;
          $obj->name = $name ;
          return $obj;
      }   
  }
  
  
  class Equipment extends XEntity
  {
      static public function bizCreate($key,$name)
      {   
          $obj = XEntity::createIns(__class__) ;
          $obj->ukey  = $key ;
          $obj->name = $name ;
          return $obj;
      }   
  }
  

3、数据库脚本

  drop table if exists `spu`;
  CREATE TABLE `spu` (
      id          int(11)         default null,
      ver         int(11)         default null,
      createtime  datetime        default null,
      updatetime  datetime        default null,
  
      ukey        varchar(50)      not null ,
      name        varchar(250)     not null ,
  
      PRIMARY     KEY (id),
      UNIQUE      KEY idx_key(ukey)  
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ;
  
  
  
  drop table if exists `equipment`;
  CREATE TABLE `equipment` (
      id          int(11)         default null,
      ver         int(11)         default null,
      createtime  datetime        default null,
      updatetime  datetime        default null,
  
      ukey        varchar(50)      not null ,
      name        varchar(255)     not null ,
  
      PRIMARY     KEY (id),
      UNIQUE      KEY idx_key(ukey)  
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ;

4、测试用例

  class EntityTest  extends PHPUnit_Framework_TestCase
  {
      public function setUp() {
          
      }   
  
      public function testBase()
      {   
          
          $xas = XAppSession::begin();
          
          Equipment::bizCreate("YITIANJIAN","倚天剑") ;
          Equipment::bizCreate("TULONGDAO","屠龙刀") ;
          SPU::bizCreate("XUEPING","血瓶");
          SPU::bizCreate("MOPING","魔瓶");
  
          $xas->commit();

          $obj = XQuery::obj()->list_spu_by_ukey("XUEPING") ;
          $xas->commit();

      }
  }

5、重复2到4步,直到完成需求

Clone this wiki locally