定制 igorv/database 二次开发

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

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

igorv/database

Composer 安装命令:

composer require igorv/database

包简介

Simple database querybuilder for PDO.

README 文档

README

Perform install using composer:

composer require igorv/database

Configuration in your bootstrap file:

require 'vendor/autoload.php';

use IgorV\Database\DB;

DB::config([
    'dsn'      => 'mysql:host=localhost;dbname=example',
    'username' => 'username',
    'password' => 'password',
    'options'  => [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]
]);

DB can now be accessed using the DB static class.

Usage

To use the query builder, call table() method containing the table your wish to query followed by other methods needed to build your query.

Select queries can be performed by appending either first() or get() method. first() returns the first record as a ResultSet object. get() returns a Collection object with the ResultsSet objects.

$user = DB::table('users')->where('id', 1)->first();

$posts = DB::table('posts')->where('visible', true)->get();

To inject query results into a different class use the as() method:

$user = DB::table('users')->sortBy('created_at', 'desc')->as(User::class)->first();

Inserting database records is done by appending insert() method at the end. Returns the number of rows affected:

$inserted = DB::table('users')->insert([
    'user'      => $user,
    'password'  => $password,
    'active'    => true
]);

Updating records is done by appending update() method. Returns the number of affected rows:

$updated = DB::table('users')->where('id', $id)->update([
    'name'  => 'John Doe',
    'age'   => 41
]);

Deleting records is done by appending delete() method. Returns the number of affected rows:

$deleted = DB::table('users')->where('age', '>', '10')->delete(); 

Counting records can be done by appending count() method. Returns the number of rows matching your query:

$number = DB::table('users')->where('active', true)->count();

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-05-31

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固