├── DatabaseAdaptor.php ├── DatabaseAdaptorTest.php ├── controller.php └── view.html /DatabaseAdaptor.php: -------------------------------------------------------------------------------- 1 | DB = new PDO($dataBase, $user, $password); 14 | $this->DB->setAttribute( 15 | PDO::ATTR_ERRMODE, 16 | PDO::ERRMODE_EXCEPTION 17 | ); 18 | } catch (PDOException $e) { 19 | echo ('Error establishing Connection'); 20 | exit(); 21 | } 22 | } // . . . continued 23 | 24 | public function getAllMovies($name) 25 | { 26 | $stmt = $this->DB->prepare("SELECT name FROM movies WHERE name LIKE '%" . trim($name) . "%';"); 27 | $stmt->execute(); 28 | return $stmt->fetchAll(PDO::FETCH_ASSOC); 29 | } 30 | 31 | public function getAllActors($name) 32 | { 33 | $stmt = $this->DB->prepare("SELECT first_name, last_name FROM actors WHERE first_name LIKE '%" . trim($name) . "%' OR last_name LIKE '%" . trim($name) . "%';"); 34 | $stmt->execute(); 35 | return $stmt->fetchAll(PDO::FETCH_ASSOC); 36 | } 37 | 38 | public function getAllRoles($name) 39 | { 40 | $stmt = $this->DB->prepare("SELECT role FROM roles WHERE role LIKE '%" . trim($name) . "%';"); 41 | $stmt->execute(); 42 | return $stmt->fetchAll(PDO::FETCH_ASSOC); 43 | } 44 | 45 | public function getAllRolesMovies($name) 46 | { 47 | list($first, $last) = explode(' ', $name); 48 | $stmt = $this->DB->prepare("SELECT name, role FROM actors JOIN roles ON actors.id = roles.actor_id JOIN movies ON roles.movie_id = movies.id WHERE first_name='" . $first . "' AND last_name='" . $last . "'"); 49 | $stmt->execute(); 50 | return $stmt->fetchAll(PDO::FETCH_ASSOC); 51 | } 52 | }// End class DatabaseAdaptor 53 | //$theDBA = new DatabaseAdaptor(); 54 | //print_r($theDBA->getMoviesReleasedSince(2004)); 55 | -------------------------------------------------------------------------------- /DatabaseAdaptorTest.php: -------------------------------------------------------------------------------- 1 | getAllMovies("will"); 7 | print_r($arr); 8 | -------------------------------------------------------------------------------- /controller.php: -------------------------------------------------------------------------------- 1 | getAllActors($_GET['name'])); 14 | break; 15 | case "movie": 16 | echo json_encode($theDBA->getAllMovies($_GET['name'])); 17 | break; 18 | case "role": 19 | echo json_encode($theDBA->getAllRoles($_GET['name'])); 20 | break; 21 | case "fullname": 22 | echo json_encode($theDBA->getAllRolesMovies($_GET['name'])); 23 | break; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /view.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Actors and Movies 7 | 22 | 23 | 24 | 25 |

26 | Search for actors, roles, movies or Roles/Movies 27 |

28 | 29 |

Search substring:
30 |

31 | 32 | 33 | 34 | 35 |
36 | 37 |

38 | Roles/Movies for actor:
39 | 40 |

41 | 42 |
43 | 44 |

45 | 46 |
47 | 48 | 118 | 119 | 120 | --------------------------------------------------------------------------------