diff --git a/03/01_lab_review/car.php b/03/01_lab_review/car.php index e69de29..c1e7d1e 100644 --- a/03/01_lab_review/car.php +++ b/03/01_lab_review/car.php @@ -0,0 +1,29 @@ +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(); + diff --git a/03/01_lab_review/connect.php b/03/01_lab_review/connect.php index e69de29..54884a4 100644 --- a/03/01_lab_review/connect.php +++ b/03/01_lab_review/connect.php @@ -0,0 +1,23 @@ +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + //if the connection is successful, then say yay! + echo "

YAY Connected

"; +} +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 */ diff --git a/03/01_lab_review/header.php b/03/01_lab_review/header.php index e502cfb..16302db 100644 --- a/03/01_lab_review/header.php +++ b/03/01_lab_review/header.php @@ -12,4 +12,4 @@

COMP1006 - Lab 1

Week 2: PHP OOP + Includes + PDO Connection

-
\ No newline at end of file +
diff --git a/03/01_lab_review/index.php b/03/01_lab_review/index.php index a791145..1b4586d 100644 --- a/03/01_lab_review/index.php +++ b/03/01_lab_review/index.php @@ -1,22 +1,6 @@ - Follow the instructions outlined in instructions.txt to complete this lab. Good luck & have fun!😀

"; -include "car.php"; +require "car.php"; require "footer.php"; \ No newline at end of file diff --git a/03/01_lab_review/instructions.txt b/03/01_lab_review/instructions.txt new file mode 100644 index 0000000..bea3373 --- /dev/null +++ b/03/01_lab_review/instructions.txt @@ -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 \ No newline at end of file diff --git a/assignments/labs/lab_one/index.php b/assignments/labs/lab_one/index.php index 222dcf8..0e4dec3 100644 --- a/assignments/labs/lab_one/index.php +++ b/assignments/labs/lab_one/index.php @@ -1,4 +1,4 @@ - Follow the instructions outlined in instructions.txt to complete this lab. Good luck & have fun!😀

"; require "footer.php"; \ No newline at end of file