Laravel 5.0 Documentation
MySQL, Postgres, SQLite, and SQL Server. Sometimes you may wish to use one database connection for SELECT statements, and another for INSERT, UPDATE, and DELETE statements. Laravel makes this a breeze, $results = DB::select('select * from users where id = ?', [1]); Basic Database Usage Configuration Read / Write Connections Running Queries Running A Select Query The select method will always connections, you may access them via the DB::connection method: $users = DB::connection('foo')->select(...); You may also access the raw, underlying PDO instance: $pdo = DB::connection()->getPdo();0 码力 | 242 页 | 1.44 MB | 1 年前3
Laravel 3.2 Documentationrecords from the database: $users = DB::query('select * from users'); Selecting records from the database using bindings: $users = DB::query('select * from users where name = ?', array('test')); simple. Here's an overview: Running a SELECT query and returning the first result: $user = DB::first('select * from users where id = 1'); Running a SELECT query and getting the value of a single single column: $email = DB::only('select email from users where id = 1'); 79 PDO Connections Sometimes you may wish to access the raw PDO connection behind the Laravel Connection object. Get0 码力 | 139 页 | 1.13 MB | 1 年前3
Laravel 5.1 中文文档查询 一旦你配置好数据库连接后,就可以使用 DB 门面来运行查询。DB 门面为每种查询提供了相 应方法:select, update, insert, delete, 和 statement。 2.1 运行 Select 查询 运行一个最基本的查询,可以使用 DB 门面的 select 方法: select('select * from users where active = ?', [1]); return view('user.index', ['users' => $users]); } } 传递给 select 方法的第一个参数是原生的 SQL 语句,第二个参数需要绑定到查询的参数绑 语句,第二个参数需要绑定到查询的参数绑 定,通常,这些都是 where 字句约束中的值。参数绑定可以避免 SQL 注入攻击。 select 方法以数组的形式返回结果集,数组中的每一个结果都是一个 PHP StdClass 对象, 从而允许你像下面这样访问结果值: foreach ($users as $user) { echo $user->name; } 本文档由 Laravel 学院(LaravelAcademy0 码力 | 307 页 | 3.46 MB | 1 年前3
Laravel 5.2 中文文档SQL 查询 配置好数据库连接后,就可以使用 DB 门面来运行查询。DB 门面为每种查询提供了相应方 法:select, update, insert, delete, 和 statement。 运行 Select 查询 运行一个最基本的查询,可以使用 DB 门面的 select 方法: select('select * from users where active = ?', [1]); return view('user.index', ['users' => $users]); } } 传递给 select 方法的第一个参数是原生的 SQL 语句,第二个参数需要绑定到查询的参数 注入攻击。 select 方法以数组的形式返回结果集,数组中的每一个结果都是一个 PHP StdClass 对 象,从而允许你像下面这样访问结果值: foreach ($users as $user) { echo $user->name; } 使用命名绑定 除了使用?占位符来代表参数绑定外,还可以使用命名绑定来执行查询: $results = DB::select('select0 码力 | 377 页 | 4.56 MB | 1 年前3
Laravel 6.0 中文文档提供的新的子查询功能,我们可以通过一个查询获 取所有的航班目的地以及最新到达这些目的地的航班名称: return Destination::addSelect(['last_flight' => Fligh t::select('name') 本文档由学院君提供 学院君致力于提供优质 Laravel 中文学习资源:https://xueyuanjun.com 10 ->whereColumn('destination_id' 方法基于到达目的地的最晚航班到达时间对所有航班目的地进行排 序,同样,这也可以通过一次数据库查询完成: return Destination::orderByDesc( Flight::select('arrived_at') ->whereColumn('destination_id', 'destinations. id') ->orderBy('arrived_at', 'desc') config/database.php 中设置的某个连接: $users = DB::connection('read')->select(...); 甚至还可以指定数据库和连接名,使用 :: 分隔: $users = DB::connection('mysql::read')->select(...); 你还可以使用连接实例上的 getPdo 方法访问底层原生的 PDO 实 例: $pdo = D0 码力 | 1442 页 | 14.66 MB | 1 年前3
Laravel 5.6 中文文档config/database.php 中设置的某个连接: $users = DB::connection('read')->select(...); 甚至还可以指定数据库和连接名,使用 :: 分隔: $users = DB::connection('mysql::read')->select(...); 你还可以使用连接实例上的 getPdo 方法访问底层原生的 PDO 实例: $pdo = 运行原生 SQL 查询 配置好数据库连接后,就可以使用 DB 门面来运行查询。DB 门面为每种操作提供了相应方法:select, update, insert, delete 和 statement。 运行 Select 查询 运行一个最基本的查询,可以使用 DB 门面的 select 方法: select('select * from users where active = ?', [1]); return view('user.index', ['users' => $users]); } } 传递给 select 方法的第一个参数是原生的 SQL 语句,第二个参数需要绑定到查询的参数绑定,通常,这些都是0 码力 | 377 页 | 14.56 MB | 1 年前3
Laravel 5.3 中文文档DB::connection('foo')->select(...); 你还可以使用连接实例上的 getPdo 方法访问底层原生的 PDO 实例: $pdo = DB::connection()->getPdo(); 2、运行原生 SQL 查询 配置好数据库连接后,就可以使用 DB 门面来运行查询。DB 门面为每种查询提供了相应方法: select, update, insert, delete delete 和 statement。 运行 Select 查询 运行一个最基本的查询,可以使用 DB 门面的 select 方法: select('select * from users where active = ?', [1]); return view('user.index', ['users' => $users]); } } 传递给 select 方法的第一个参数是原生的 SQL 语句,第二个参数需要绑定到查询的参数绑定,0 码力 | 691 页 | 9.37 MB | 1 年前3
Learning Laravelthat matches the view names for which to register the composer (* being a wildcard). You can also select a single view (e.g. 'home') of a group of routes under a subfolder (e.g. 'users.*'). Execute arbitrary needed. If no array is specified on creation, an empty Collection will be created. where() You can select certain items out of a collection by using the where() method. $data = [ ['name' => 'Taylor' 'coffee_drinker' => true] ]; $matt = collect($data)->where('name', 'Matt'); This bit of code will select all items from the collection where the name is 'Matt'. In this case, only the second item is returned0 码力 | 216 页 | 1.58 MB | 1 年前3
《Slides Dev Web》02. Introduction aux frameworks PHP
charset=utf-8>HE-Arc query("SELECT * FROM `personnes` WHERE `id` = :id;"); $query->execute(compact('id')); $personne = $query->fetch(PDO::FETCH_OBJ); 01-includes/index.php // ... include "templates/entete.html"; if ("equipe" === $_GET["page"]) { // SELECT FROM u WHERE id=$_GET["id"] // ... include "templates/equipe.html"; } else { // ... include "templates/accueil Object-Relational Mapping ou ORM(3) dans le jargon. query( "SELECT * FROM `personnes` ". "WHERE `id` = :id;" ); $query->execute(compact('id')); $personne = $query0 码力 | 24 页 | 1.03 MB | 1 年前3
《Slides Dev Web》 12. Risques applicatifs
pour l’exploiter • SQL est puissant : UNION, INTO DUMPFILE, … Exemples10 SELECT titre, num FROM livres WHERE num=2 UNION SELECT login, password FROM user INTO DUMPFILE 'www/exploit.txt' Eviter les injections0 码力 | 12 页 | 474.37 KB | 1 年前3
共 12 条
- 1
- 2













