HTML, PHP, MySQL Exercises

Download Report

Transcript HTML, PHP, MySQL Exercises

CpSc 3220
HTML, PHP, MySQL Exercises
Chapter 19
Murach’s PHP and MySQL
Exercises from Chapter 19
1. Ask us to study and modify a Web site that works with the
my_guitar_shop1 database
2. The MVC pattern was used to create this Web site
3. It is coded using HTML, PHP, and MySQL
Murach's PHP and MySQL, C5
© 2010, Mike Murach & Associates, Inc.
Slide 2
The MVC pattern
Murach's PHP and MySQL, C5
© 2010, Mike Murach & Associates, Inc.
Slide 3
c:/xampp/htdocs/ex_starts/ch19_ex1
Murach's PHP and MySQL, C19
© 2010, Mike Murach & Associates, Inc.
Slide 4
index.php
<?php
require('util/main.php');
require('model/database.php');
require('model/product_db.php');
// Select some products
$category_id = 2;
// Get the products
$products = get_products_by_category($category_id);
//Delete a product
$name = 'Fender Telecaster';
// Delete the product and display an appropriate message
$delete_message = "No rows were deleted.";
// Insert a product
$category_id = 1;
$code = 'tele';
$name = 'Fender Telecaster';
$description = 'NA';
$price = '949.99';
// Insert the data and Display an appropriate message
$insert_message = "No rows were inserted.";
include 'home.php';
?>
database.php
<?php
$dsn = 'mysql:host=localhost:3307;dbname=my_guitar_shop2';
$username = 'mgs_user';
$password = 'pa55word';
$options = array(PDO::ATTR_ERRMODE =>
PDO::ERRMODE_EXCEPTION);
try {
$db = new PDO($dsn, $username, $password, $options);
} catch (PDOException $e) {
$error_message = $e->getMessage();
include 'errors/db_error_connect.php';
exit;
}
function display_db_error($error_message) {
global $app_path;
include 'errors/db_error.php';
exit;
}
?>