[转]Illuminate Database
本文转自:https://github.com/illuminate/database
Illuminate Database
The Illuminate Database component is a full database toolkit for PHP, providing an expressive query builder, ActiveRecord style ORM, and schema builder. It currently supports MySQL, Postgres, SQL Server, and SQLite. It also serves as the database layer of the Laravel PHP framework.
Usage Instructions
First, create a new "Capsule" manager instance. Capsule aims to make configuring the library for usage outside of the Laravel framework as easy as possible.
use Illuminate\Database\Capsule\Manager as Capsule; $capsule = new Capsule; $capsule->addConnection([
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'database',
'username' => 'root',
'password' => 'password',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
]); // Set the event dispatcher used by Eloquent models... (optional)
use Illuminate\Events\Dispatcher;
use Illuminate\Container\Container;
$capsule->setEventDispatcher(new Dispatcher(new Container)); // Make this Capsule instance available globally via static methods... (optional)
$capsule->setAsGlobal(); // Setup the Eloquent ORM... (optional; unless you've used setEventDispatcher())
$capsule->bootEloquent();
composer require "illuminate/events"required when you need to use observers with Eloquent.
Once the Capsule instance has been registered. You may use it like so:
Using The Query Builder
$users = Capsule::table('users')->where('votes', '>', 100)->get();
Other core methods may be accessed directly from the Capsule in the same manner as from the DB facade:
$results = Capsule::select('select * from users where id = ?', array(1));
Using The Schema Builder
Capsule::schema()->create('users', function ($table) {
$table->increments('id');
$table->string('email')->unique();
$table->timestamps();
});
Using The Eloquent ORM
class User extends Illuminate\Database\Eloquent\Model {}
$users = User::where('votes', '>', 1)->get();
For further documentation on using the various database facilities this library provides, consult the Laravel framework documentation.
[转]Illuminate Database的更多相关文章
- 优雅使用 illuminate/database 包中的 Collection
优雅使用 illuminate/database 包中的 Collection 或许你很抵抗使用 Laravel , 但是你没有理由不喜欢使用 illuminate/database.这是一个 ORM ...
- 【laravel5.6】 Illuminate\Database\QueryException : SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes
在进行数据迁移时候报错: 特殊字段太长报错, php artisan migrate 现在utf8mb4包括存储emojis支持.如果你运行MySQL v5.7.7或者更高版本,则不需要做任何事情. ...
- [Illuminate\Database\QueryException] SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using pas sword: NO) (SQL: select * from information_schema.tables where table_schema = la
[Illuminate\Database\QueryException] SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost ...
- Undefined property: Illuminate\Database\Eloquent\Builder
是因为在 $activity=Activity::where('center_id','=',$center->id)->where('Date','=',date("Y-m-d ...
- laravel Tinker报错 BadMethodCallException with message 'Call to undefined method Illuminate\Database\Query\Builder
进行模型关联操作, php artisan tinker 执行 $user = App\Models\User::find(1) $user->followings()->attach([ ...
- laravel执行数据库迁移的过程中出现Illuminate\Database\QueryException : SQLSTATE[HY000] [2002] Operation timed out (SQL: select * from information_schema.tables where table_schema = shop and table_name = migrations
向customers表添加字段phone php artisan make:migration add_phone_to_customers_table 问题: 解决方法: 将DB_HOST配置项修改 ...
- Database ORM
Database ORM Introduction Basic Usage Mass Assignment Insert, Update, Delete Soft Deleting Timestamp ...
- Argument 1 passed to Illuminate\Auth\SessionGuard::login() must be an instance of Illuminate\Contracts\Auth\Authenticatable, instance of App\User given,
使用laravel内置的注册认证系统,注册账号,提示如下错误.Google之后,发现github的一个答案,解决了.分享一下 Argument 1 passed to Illuminate\Auth\ ...
- [php]laravel框架容器管理的一些要点
本文面向php语言的laravel框架的用户,介绍一些laravel框架里面容器管理方面的使用要点.文章很长,但是内容应该很有用,希望有需要的朋友能看到.php经验有限,不到位的地方,欢迎帮忙指正. ...
随机推荐
- VS Code 之 smarty 扩展
VS Code 中的 Smarty 扩展: https://github.com/imperez/vscode-smarty 目前(v0.2.0)不支持定制定界符.可以通过 trick 的方式篡改. ...
- 201671010147 2017年8月27号 初学java的感想
在IT行业中,java无疑是最热门的,很多企业也青睐java,因为他的扩展性好,可以处理更多客户的数据,正是因为java有前景所以才吸引更多人去学习.在大一我们已经接触vhleC语言,大二开始就解除了 ...
- 2017年7月最新浏览器市场份额,IE8份额仅剩个位数
数据来源为百度统计所覆盖的超过150万的站点,样本为2017年6月1日-2017年6月30日最新一个月的数据. 统计如下: 其中IE8的份额为9.83%,首次降至个位数.在所有IE版本中,份额最高的是 ...
- 【每日一点】1. Java如何实现导出Excel单表头或多表头
一.背景 在后台项目中,经常会遇到将呈现的内容导出到Excel的需求,通过都是导出单个表头的Excel文件,如果存在级联关系的情况下,也就需要导出多表头的场景.今天这篇文章就是分享导出Excel单表头 ...
- Android X 相关汇总
一.说明 官方原文如下: We hope the division between android.* and androidx.* makes it more obvious which APIs ...
- Android Studio 3.0 变化之 implementation与compile
Android Studio 3.0 出来很久了,本文就着重介绍一下 新版本中 Moudle 中 build.gradle 文件中的变化. 我们来看看新建一个项目在 Moudle 中的 depende ...
- Python面向对象3:面向对象的三大特性
面向对象的三大特性- 封装- 继承- 多态1 封装 - 封装就是对对象的成员进行访问限制- 封装的三个级别: - 公开,public - 受保护的,protected - 私有的,private - ...
- python_正则表达式概述
正则表达式(RegularExpression, re) - 是一个计算机科学的概念- 用于使用单个字符串来描述,匹配符合某个规则的字符串- 常常用来检索,替换某些模式的文本 # 正则的写法- .(点 ...
- Spring Boot 返回 XML 数据,一分钟搞定!
Spring Boot 返回 XML 数据,前提必须已经搭建了 Spring Boot 项目,所以这一块代码就不贴了,可以点击查看之前分享的 Spring Boot 返回 JSON 数据,一分钟搞定! ...
- SpringBoot2.1整合finereport10(帆软报表)
最近,公司采购了帆软的系统,领导安排要与公司的SpringBoot框架进行整合.费了一番牛劲,终于整合成功,下面分享一下我的经验. 首先,我的开发环境是Intellij IDEA,使用的SpringB ...