diff --git a/03/01_lab_review/car.php b/03/01_lab_review/car.php index e69de29..36f0539 100644 --- a/03/01_lab_review/car.php +++ b/03/01_lab_review/car.php @@ -0,0 +1,27 @@ +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); + +//cal the getCar() method and echo/display in browser +echo $car->getCar(); \ No newline at end of file diff --git a/03/01_lab_review/connect.php b/03/01_lab_review/connect.php index e69de29..20e1ad8 100644 --- a/03/01_lab_review/connect.php +++ b/03/01_lab_review/connect.php @@ -0,0 +1,24 @@ +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + echo "

YAY Connected!

"; +} +//this is what happens when things go wrong +catch (PDOException $e) { + //stop the script and display a helpful error message + die ("Database connection failed: " .$e->getMessage()); +} + + + + diff --git a/03/01_lab_review/index.php b/03/01_lab_review/index.php index a791145..f769927 100644 --- a/03/01_lab_review/index.php +++ b/03/01_lab_review/index.php @@ -1,5 +1,5 @@ Follow the instructions outlined in instructions.txt to complete this lab. Good luck & have fun!😀

"; include "car.php"; require "footer.php"; \ No newline at end of file diff --git a/03/02_fix_this_code/index.php b/03/02_fix_this_code/index.php index 19aa44c..0300d50 100644 --- a/03/02_fix_this_code/index.php +++ b/03/02_fix_this_code/index.php @@ -4,21 +4,18 @@ error_reporting(E_ALL); -$host = "localhost" - +$host = "localhost"; $dbname = "week_two"; $username = "root"; $password = ""; -$dsn = "mysql:host=$hostdbname=$dbname"; +$dsn = "mysql:host=$host;dbname=$dbname"; try { - - $pdo = new PDO($dsn $username,); - $pdo->setAttribute(PDO::ATTR_ERRMODE PDO::ERRMODE_SILENT); - - echo "Connected to database!"; - -catch (PDOException $e { - echo "Database error: " . $e + $pdo = new PDO($dsn, $username, $password); + $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + echo "

Connected to a database !

"; +} +catch (PDOException $e){ + echo "Database error: " . $e->getMessage(); }