Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions 03/01_lab_review/car.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

class Car
{

// these are the properties, public makes them accessible outside of the class
public string $make;
public string $model;
public int $year;

public function __construct(string $make, string $model, int $year)
{
$this->make = $make;
$this->model = $model;
$this->year = $year;
}

//method
public function getCar(): string
{
return "Make : {$this->make} | Model : {$this->model} | Year: {$this->year}";
}
}

//create a new car object
$car = new Car("Honda", "Civic", 2010);

echo $car->getCar();

23 changes: 23 additions & 0 deletions 03/01_lab_review/connect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
//Database connection settings
$host = "localhost";
$db = "week_three";
$user = "root";
$password = "";

//DSN - Data Source Name
$dsn = "mysql:host=$host;dbname=$db";

try {
//Create PDO object
//attempting to connect to the database
$pdo = new PDO($dsn, $user, $password);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//if the connection is successful, then say yay!
echo "<p> YAY Connected </p>";
}
catch(PDOException $e) {
die("Database connection failed: " . $e->getMessage());
}

/*PDO tries to connect, if it fails, PHP creates an PDOException object and that object contains an error message */
2 changes: 1 addition & 1 deletion 03/01_lab_review/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
<body>
<h1>COMP1006 - Lab 1</h1>
<p>Week 2: PHP OOP + Includes + PDO Connection</p>
<hr>
<hr>
24 changes: 4 additions & 20 deletions 03/01_lab_review/index.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
<?php

/*

Lab One Instructions:

1.) Clone or download the Lab One starter files from the course GitHub repository.
2.) Create a PHP file called car.php. In this file, create a class to represent a car. Properties should include make, model and year and include a method to return this information. Use include/require to include this code in index.php. Add comments to explain your code. (/5 marks)
3.) Instantiate a new instance of a car object and echo the car information in the browser (/2 marks)
4.) Using your local server (XAMPP, MAMP, WAMP), create a database. Create a file called connect.php and use PDO to connect to your database. Remember to include try/catch blocks to handle connection errors. Use include/require to include this code in index.php. Add comments to explain your code (/5 marks)
6.) Add a multi-line comment in index.php reflecting on which parts of the lab you found easy and which parts were challening. (/2 marks)
7.) Congrats! All done! Add me as a collaborator to your repository (username: JessicaGilfilan) and submit a github link to your completed lab on Blackboard. (/2 marks)

/16 marks

*/

require "header.php";
require "connect.php";
<?php
require "connect.php";
require "header.php";
echo "<p> Follow the instructions outlined in instructions.txt to complete this lab. Good luck & have fun!😀 </p>";
include "car.php";
require "car.php";
require "footer.php";
10 changes: 10 additions & 0 deletions 03/01_lab_review/instructions.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Lab One Instructions:

1.) Clone or download the Lab One starter files from the course GitHub repository.
2.) Create a PHP file called car.php. In this file, create a class to represent a car. Properties should include make, model and year and include a method to return this information. Use include/require to include this code in index.php. Add comments to explain your code. (/5 marks)
3.) Instantiate a new instance of a car object and echo the car information in the browser (/2 marks)
4.) Using your local server (XAMPP, MAMP, WAMP), create a database. Create a file called connect.php and use PDO to connect to your database. Remember to include try/catch blocks to handle connection errors. Use include/require to include this code in index.php. Add comments to explain your code (/5 marks)
6.) Add a multi-line comment in index.php reflecting on which parts of the lab you found easy and which parts were challening. (/2 marks)
7.) Congrats! All done! Add me as a collaborator to your repository (username: JessicaGilfilan) and submit a github link to your completed lab on Blackboard. (/2 marks)

/16 marks
2 changes: 1 addition & 1 deletion assignments/labs/lab_one/index.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php
require "header.php";
echo "<p> Follow the instructions outlined in instructions.txt to complete this lab. Good luck & have fun!😀 </p>";
require "footer.php";