博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[转]Illuminate Database
阅读量:6246 次
发布时间:2019-06-22

本文共 2018 字,大约阅读时间需要 6 分钟。

本文转自:

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 .

 

转载地址:http://hmoia.baihongyu.com/

你可能感兴趣的文章
mysqldump参数详解
查看>>
new begin
查看>>
List集合按Size分组
查看>>
windows下安装jandgo
查看>>
【译】你可以用GitHub做的12件 Cool 事情
查看>>
看图你就明白一个光棍的道理 [图片]
查看>>
ul宽度不固定,li的数量不定要保持居中???
查看>>
mysql多实例的作用和问题
查看>>
[置顶] ApplicationResources_zh_CN.properties乱码问题
查看>>
我的友情链接
查看>>
当寂寞不得不成为一种习惯
查看>>
oracle的序列号(sequence)
查看>>
MyEclipse启动tomcat发生Socket bind failed: [730048]
查看>>
树莓派连接到手机屏幕
查看>>
MyBatis学习整理0
查看>>
[转载]不再让你孤单
查看>>
登录验证的生成类RandomCodeRender
查看>>
singleton
查看>>
smarty插件判断图片是否存在,不存在则调用默认图片
查看>>
[转载] 晓说——第29期:海上霸主航母(上)
查看>>