定制 jimonade/pdope 二次开发

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

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

jimonade/pdope

Composer 安装命令:

composer require jimonade/pdope

包简介

A composer package that provides solutions for simplifying PDO query parameterization

README 文档

README

php pdo practical extensions for simple 1-table mvc models

this helper class is required in your model's base class

class DataProperty {
  public $name;
  private $type;
  public $required;

  function __construct($name, $type=NULL, $required=FALSE) {
    $this->name = $name;
    if (empty($type)) {
      $type = "STRING";
    }
    $this->type = $type;
    $this->required = $required;
  }
  public function set_type($type) {
    $this->type = strtoupper($type);
  }
  public function get_type() {
    return $this->type;
  }
}

first, define data properties in your model constructor

  function __construct($props=null) {
    parent:: __construct($props);

    $this->define_data_property("id", "STRING", TRUE);
    $this->define_data_property("title", "STRING", FALSE);
    $this->define_data_property("description", "STRING", FALSE);
    $this->define_data_property("organization_id", "STRING", FALSE);
    $this->define_data_property("address_line_1", "STRING", FALSE);
    $this->define_data_property("address_line_2", "STRING", FALSE);
    $this->define_data_property("address_line_3", "STRING", FALSE);
    $this->define_data_property("city", "STRING", FALSE);
    $this->define_data_property("state", "STRING", FALSE);
    $this->define_data_property("zip", "STRING", FALSE);
    $this->define_data_property("capacity", "INT", FALSE);
    $this->define_data_property("latitude", "FLOAT", FALSE);
    $this->define_data_property("longitude", "FLOAT", FALSE);
    $this->define_data_property("created_at", "DATE", FALSE);
    $this->define_data_property("updated_at", "DATE", FALSE);
    $this->define_data_property("active", "BOOL", FALSE);
  }

example, simple query

  $db = new \PDope\Statement("select", "facility", $this);
  $db->add_where_parameters_auto(TRUE);
  return $db->execute();

example, simple insert

  $db = new \PDope\Statement("insert", "facility", $this);
  $db->add_parameters_auto(TRUE);
  $db->add_parameter("id", "UUID");
  $db->add_parameter("created_at", "NOW");
  $db->add_parameter("updated_at", "NOW");
  $db->execute();

example, simple update

  $db = new \PDope\Statement("update", "facility", $this);
  $db->add_parameters_auto(TRUE);

  //we dont want to update "id" or "created_at"
  $db->remove_parameter("id");
  $db->remove_parameter("created_at");

  $db->add_parameter("updated_at", "NOW");
  $db->add_where_parameter("id", "STRING");
  $db->execute();

example, simple suspend

  $db = new \PDope\Statement("update", "facility", $this);
  $db->add_parameter("updated_at", "NOW");
  $db->add_parameter("active");
  $db->add_where_parameter("id");
  $db->execute();

example, you can always just use the pdo object to build your own statement from scratch

$pdo = \PDope\Connection:: connection();
$statement = $pdo->prepare("SELECT property FROM table WHERE id = :id");
$statement->execute(['id' => $model->id]);
$results = $statement->fetchAll(\PDO::FETCH_OBJ);

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-06-01

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固