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'
);