<?php include_once "_config.php"; include_once "../../src/database/DB.php"; include_once "../../src/database/Statement.php"; include_once "../../src/database/Query.php"; $db = new database\DB(DB_DSN, DB_USER, DB_PASS); class Film { public $film_id; public $title; } $category_name = "Action"; $stmt = $db->select("f.film_id, f.title")->from("film f")->join("INNER JOIN film_category fc ON fc.film_id = f.film_id")->join("INNER JOIN category c ON c.category_id = fc.category_id")->where("c.name = ?", $category_name)->limit(5)->execute(); while ($film = $stmt->fetchInto(new Film())) { var_dump($film); }
include_once "../../src/database/DB.php"; include_once "../../src/database/Statement.php"; include_once "../../src/database/Query.php"; class Customer { } class City { } class Address { } class Store { } $db = new database\DB(DB_DSN, DB_USER, DB_PASS); $db->setFetchTableNames(1); $stmt = $db->select("c.customer_id, c.first_name, c.last_name")->from("customer c")->limit(5)->select("ca.address, ca.postal_code, ca.phone")->join("INNER JOIN address ca ON ca.address_id = c.address_id")->select("city.city")->join("INNER JOIN city ON city.city_id = ca.city_id")->select("s.store_id, sa.address")->join("INNER JOIN store s ON s.store_id = c.store_id")->join("INNER JOIN address sa ON sa.address_id = s.address_id")->where("c.customer_id > ?", 120)->where("c.customer_id < ?", 345)->execute(); $customers = array(); while ($customer = $stmt->fetchInto(new Customer(), "c")) { $customer->address = $stmt->fetchIntoFromLastRow(new Address(), "ca"); $customer->address->city = $stmt->fetchIntoFromLastRow(new City(), "city"); $customer->store = new Store(); $stmt->fetchIntoFromLastRow($customer->store, "s"); $stmt->fetchIntoFromLastRow($customer->store, "sa"); $customers[] = $customer; } $db->setFetchTableNames(0); // reset to default echo "<pre>"; print_r($customers);