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
27 changes: 27 additions & 0 deletions 03/01_lab_review/car.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
class Car {
//properties
public string $make;
public string $model;
public int $year;

//constructor function
public function __construct(string $make, string $model, int $year) {
//$this refers to the current instance of the object
//these assignments bind the incoming arguments to the object's properties
$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);

//cal the getCar() method and echo/display in browser
echo $car->getCar();
24 changes: 24 additions & 0 deletions 03/01_lab_review/connect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
//store db connection info in a variable
$host = "localhost"; //hostname
$db = "lab_one";
$user = "root";
$pword = "";
//data source name - type of db, location and db name
$dsn = "mysql:host=$host;dbname=$db";

//what we want to happen
try {
$pdo = new PDO($dsn, $user, $pword);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "<p> YAY Connected! </p>";
}
//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());
}




3 changes: 1 addition & 2 deletions 03/01_lab_review/index.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

require "connect.php";
/*

Lab One Instructions:
Expand All @@ -16,7 +16,6 @@
*/

require "header.php";
require "connect.php";
echo "<p> Follow the instructions outlined in instructions.txt to complete this lab. Good luck & have fun!😀 </p>";
include "car.php";
require "footer.php";
19 changes: 8 additions & 11 deletions 03/02_fix_this_code/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<p>Connected to a database ! </p>";
}
catch (PDOException $e){
echo "Database error: " . $e->getMessage();
}