Example #1
0
{
    const TABLE = "testusers2";
    const VERSION = 'modified_on';
    const MODULE_NAME = "test";
    const KEY_NAME = "id";
    const F_ID = "id";
    const CLASS_NAME = 'yangzie\\UserModel';
    const F_TITLE = "title";
    const F_CREATED_ON = "created_on";
    const F_MODIFIED_ON = "modified_on";
    public static $columns = array('id' => array('type' => 'integer', 'null' => false, 'length' => '11', 'default' => ''), 'name' => array('type' => 'string', 'null' => false, 'length' => '201', 'default' => ''), 'register_time' => array('type' => 'date', 'null' => false, 'length' => '', 'default' => ''), 'email' => array('type' => 'string', 'null' => false, 'unique' => true, 'length' => '45', 'default' => ''), 'created_on' => array('type' => 'date', 'null' => true, 'length' => '', 'default' => ''), 'modified_on' => array('type' => 'TIMESTAMP', 'null' => false, 'length' => '', 'default' => 'CURRENT_TIMESTAMP'));
}
/**
 * 初始化数据
 */
YZE_DBAImpl::getDBA()->migration(UserModel::CLASS_NAME);
UserModel::truncate();
/**
 * 这里的测试需要配置数据库连接
 */
$db = \yangzie\YZE_DBAImpl::getDBA();
$user = new UserModel();
$user->set("name", "aa");
$user->set("email", "333333");
$user->set("register_time", "2015-12-17 17:50:30");
$user->save();
//测试插入新数据
$insert_key = $user->get_key();
echo $insert_key >= 1 ? "insert true" : "insert false";
try {
    $user->set("id", null);
Example #2
0
 /**
  * 清空表中所有数据,主键重新从1开始
  */
 public static function truncate()
 {
     $sql = "TRUNCATE `" . YZE_MYSQL_DB . "`.`" . static::TABLE . "`;";
     YZE_DBAImpl::getDBA()->exec($sql);
 }