定制 subztep/modell 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

subztep/modell

最新稳定版本:v1.0

Composer 安装命令:

composer require subztep/modell

包简介

Model class for PDO

README 文档

README

A PHP class for easily create/update/load database entries. All you need to do is extend this class from your model and enjoy the benefits. It uses PDO connection but I only tested with MySql. I am going to explain the usage with a simple user class.

Please write your tests well.

Installation

Extend your composer.json file with the following:

{
  "require": {
    "subztep/modell": "dev-master"
  }
}

Create data table

Our user table will contains name and email. Each plural table require an id int primary key field. Optional created_at and updated_at datetime columns for log your updates, recommended.

CREATE TABLE `users` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `name` varchar(30) NOT NULL,
 `email` varchar(255) DEFAULT NULL,
 `created_at` datetime DEFAULT NULL,
 `updated_at` datetime DEFAULT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Usage with PHP

Connect to database

Modell::$pdo = new PDO('mysql:host=HOST;dbname=DBNAME;charset=utf8', 'USER', 'PASS');

Connect to memcache is optional. If connected, Modell cache your table's column details and make it faster.

Modell::$memcache = new Memcache;
Modell::$memcache->connect('localhost', 11211);

Create table users with primary key id, and add Modell class to your project

class User extends Modell {
}

Furthermore, you can run any sql query, connection in singleton.

$query = Modell::$pdo->prepare($sql);

Examples

Create user

$user = new User();
$user->name = 'John Doe';
$user->save();

Load user by id

$user = new User(1);
echo $user->name;

Update user by id

$user = new User(1);
$user->name = 'John Roe';
$user->save();

统计信息

  • 总下载量: 18
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 3
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2015-05-25