Slide 1

Slide 1 text

8IZEPO`UZPVUSZ 2VFSZ#VJMEFS 1)1$POGFSFODF'VLVPLB .BZ  4PUBSP0.63"

Slide 2

Slide 2 text

"CPVU.F w4PUBSP0.63" w0TBLB +BQBO w,BOTBJ1)16TFST(SPVQ4UB⒎ w1)1   w-BSBWBM wPNPPOPSH w!PNPPO

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

2VFSZ#VJMEFS

Slide 5

Slide 5 text

2VFTUJPOT w%PZPVLOPX42-  w.Z42-1PTUHSF42-0SBDMFPUIFST  w1%0 w,OPX2VFSZ#VJMEFS w6TF2VFSZ#VJMEFS w6TF03.

Slide 6

Slide 6 text

/PUF w1%0 w*MMVNJOBUF%BUBCBTF w.Z42-

Slide 7

Slide 7 text

4BNQMF%BUBCBTF

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

5PQJDT w8IBUJTl2VFSZ#VJMEFSz  w#FOFpUT w)PXUPBQQMZ2VFSZ#VJMEFSUPZPVSPXOBQQ w4PNFFYBNQMFT

Slide 10

Slide 10 text

8IBU`T 2VFSZ#VJMEFS

Slide 11

Slide 11 text

1JD DPOTUSVDUJPO

Slide 12

Slide 12 text

1JD DPOTUSVDUJPO

Slide 13

Slide 13 text

"UPPMUPCVJME42-

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

SELECT name, price
 FROM books
 WHERE name LIKE '%PHP%'
 ORDER BY price DESC
 LIMIT 10

Slide 16

Slide 16 text

SELECT name, price
 FROM books
 WHERE name LIKE '%PHP%'
 ORDER BY price DESC
 LIMIT 10

Slide 17

Slide 17 text

&BDIQBSUPG42- IBTB30-&

Slide 18

Slide 18 text

$builder->table('books')
 ->where('name', 'like', '%PHP%')
 ->orderBy('name', 'desc')
 ->take(10) ->select('name', 'price');

Slide 19

Slide 19 text

SELECT `name`, `price`
 FROM `books`
 WHERE `name` LIKE '%PHP%'
 ORDER BY `price` DESC
 LIMIT 10

Slide 20

Slide 20 text

DELETE FROM `books`
 WHERE `name` LIKE '%PHP%'
 ORDER BY `price` DESC
 LIMIT 10

Slide 21

Slide 21 text

$builder->table('books')
 ->where('name', 'like', '%PHP%')
 ->orderBy('price', 'desc')
 ->take(10) ->select('name', 'price');

Slide 22

Slide 22 text

$builder->table('books')
 ->where('name', 'like', '%PHP%')
 ->orderBy('price', 'desc')
 ->take(10) ->delete();

Slide 23

Slide 23 text

$builder->table('books')
 ->where('name', 'like', '%PHP%')
 ->orderBy('price', 'desc')
 ->take(10) ->select('name', 'price');

Slide 24

Slide 24 text

$builder->table('books')
 ->where('name', 'like', '%PHP%')
 ->orderBy('price', 'desc')
 ->take(10) ->select('name', ‘price') ->get();

Slide 25

Slide 25 text

#FOFpUT

Slide 26

Slide 26 text

#FOFpUT w&BTZUPFEJU w4FDVSF w&BTZUPSFBE w3FVTBCMF

Slide 27

Slide 27 text

&BTZUPFEJU

Slide 28

Slide 28 text

%FNP

Slide 29

Slide 29 text

4FDVSF

Slide 30

Slide 30 text

$name = 'PHPΤϯδχΞཆ੒ಡຊ'; 
 $sql = "
 SELECT `name`, `price` 
 FROM `books` 
 WHERE `name` = $name
 ORDER BY `price` DESC ";
 
 $sth = $pdo->prepare($sql);
 $sth->execute();

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

$name = "t' OR 't' = 't";
 
 $sql = <<<'SQL'
 SELECT `name`, `price`
 FROM `books`
 WHERE `name` = $name
 ORDER BY `price` DESC
 SQL;
 
 $sth = $pdo->prepare($sql);
 $sth->execute();

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

$name = "t' OR 't' = 't";
 
 $sql = <<prepare($sql);
 $sth->execute([$name]);

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

$name = "t' OR 't' = 't"; 
 $builder->table('books')
 ->select('name', 'price')
 ->where('name', '=', $name)
 ->orderBy('name', 'desc');

Slide 38

Slide 38 text

&BTZUPSFBE

Slide 39

Slide 39 text

SELECT `name`, `price` 
 FROM `books` 
 WHERE `name` LIKE ‘%PHP%' AND `price` > 2000
 ORDER BY `price` DESC 
 LIMIT 10

Slide 40

Slide 40 text

$sql = "
 SELECT `name`, `price` 
 FROM `books` 
 WHERE `name` LIKE :name
 AND `price` > :price 
 ORDER BY `price` DESC 
 LIMIT :limit 
 ";
 
 $sth = $pdo->prepare($sql);
 $sth->bindParam(':name', $name);
 $sth->bindParam(':price', $price);
 $sth->bindParam(':limit', $limit, PDO::PARAM_INT);
 $sth->execute();

Slide 41

Slide 41 text

$name = '%PHP%';
 $price = 2000;
 $limit = 10; 
 $sql = "SELECT `name`, `price` 
 FROM `books` 
 WHERE `name` LIKE ? AND `price` > ?
 ORDER BY `price` DESC 
 LIMIT ?";
 
 $sth = $pdo->prepare($sql);
 $sth->execute([$name, $price, $limit]);

Slide 42

Slide 42 text

$name = '%PHP%';
 $price = 2000; $limit = 10;
 
 $builder->table('books')
 ->select('name', 'price')
 ->where('name', 'like', $name)
 ->where('price', '>', $price)
 ->orderBy('name', 'desc')
 ->take($limit);

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

3FVTBCMF

Slide 45

Slide 45 text

SELECT `name`, `price` 
 FROM `books` 
 WHERE `price` < 2000

Slide 46

Slide 46 text

$cheap_books =
 $builder->table('books')
 ->where('price', '<', 2000);

Slide 47

Slide 47 text

$cheap_books->orderBy('name');
 $cheap_books->orderBy('price');
 $cheap_books->orderBy('price', 'desc');
 $cheap_books->orderBy('price', ‘desc') ->take(10);

Slide 48

Slide 48 text

$cheap_books->orderBy('price', ‘desc') ->take(10) ->select();

Slide 49

Slide 49 text

$cheap_books->orderBy('price', ‘desc') ->take(10) ->delete();

Slide 50

Slide 50 text

$cheap_books->count();
 $cheap_books->max('price');
 $cheap_books->min('price');
 $cheap_books->average('price');
 $cheap_books->sum('price');

Slide 51

Slide 51 text

#FOFpUT w&BTZUPFEJU w4FDVSF w&BTZUPSFBE w3FVTBCMF

Slide 52

Slide 52 text

)PXUPBQQMZ 2VFSZ#VJMEFS UPZPVSPXOBQQT

Slide 53

Slide 53 text

{
 "require": {
 "illuminate/database": "5.2.*"
 }
 }

Slide 54

Slide 54 text

require_once '/path/to/vendor/autoload.php';

Slide 55

Slide 55 text

use Illuminate\Database\Capsule\Manager as Builder; class Connection
 {
 private $host = 'localhost';
 private $username = 'user';
 private $password = 'pass';
 private $database = 'database';
 public function getBuilder()
 {
 $builder = new Builder();
 $builder->addConnection([
 'driver' => 'mysql',
 'host' => $this->host,
 'database' => $this->database,
 'username' => $this->username,
 'password' => $this->password,
 'charset' => 'utf8',
 'collation' => 'utf8_unicode_ci',
 'prefix' => '',
 ]);
 $builder->setAsGlobal();
 $builder->setFetchMode(PDO::FETCH_ASSOC);
 return $builder->connection();
 }
 } $builder = (new Connection())->getBuilder();

Slide 56

Slide 56 text

4PNFNPSFFYBNQMFT

Slide 57

Slide 57 text

+0*/

Slide 58

Slide 58 text

SELECT
 `books`.`name` AS `book_name`,
 `books`.`price`,
 `authors`.`name` AS `author_name`,
 `authors`.`age`
 FROM `books` LEFT JOIN `authors`
 ON `books`.`author_id` = `authors`.`id`
 WHERE `books`.`price` >= ?

Slide 59

Slide 59 text

$results = $builder->table('books')
 ->leftJoin('authors', 'books.author_id', '=', 'authors.id')
 ->where('books.price', '>=', 5000)
 ->select(
 'books.name as book_name',
 'books.price',
 'authors.name as author_name',
 'authors.age'
 );

Slide 60

Slide 60 text

*/4&35

Slide 61

Slide 61 text

$values = [];
 for ($i = 0; $i < 10000; $i++) {
 $values[] = [
 'name' => 'name' . $i,
 'author_id' => rand(1, 10),
 'price' => rand(500, 10000),
 ];
 }
 
 $sql = "INSERT INTO books (name, author_id, price) values (?, ?, ?)”; 
 $sth = $pdo->prepare($sql);
 foreach ($values as $value) {
 $sth->execute(array_values($value));
 }
 
 $builder->table('books')->insert($values);

Slide 62

Slide 62 text

INSERT INTO `books`(`name`, `author`, `price`) VALUES(?, ?, ?)
 .
 .
 .
 VS 
 INSERT INTO `books`(`name`, `author`, `price`) VALUES(?, ?, ?),(?, ?, ?),(?, ?, ?)......

Slide 63

Slide 63 text

NZTRMJ T 1%0 T 2VFSZ#VJMEFS NT

Slide 64

Slide 64 text

61%"5&3"8

Slide 65

Slide 65 text

UPDATE `books`
 SET `name` = CONCAT('ʲ͍҆Αʂʳ', `name`)
 WHERE `price` < 3000

Slide 66

Slide 66 text

$cheap_books->update([
 'name' =>"CONCAT('ʲ͍҆Αʂʳ' , `name`)"
 ]);

Slide 67

Slide 67 text

No content

Slide 68

Slide 68 text

$cheap_books->update([
 'name' => $builder->raw( "CONCAT('ʲ͍҆Αʂʳ' , `name`)" )
 ]);

Slide 69

Slide 69 text

No content

Slide 70

Slide 70 text

"OZ2VFTUJPOT