Skip to content
Open
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
17 changes: 8 additions & 9 deletions sites/intro-to-php/creating_a_data_class.step
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ steps do
end

step do
message "Now create a connect function:"
message "Now create a constructor that will assign a PDO instance to a class variable:"

source_code :php, <<-PHP
<?php
class TopicData {
protected $connection;

public function connect()
public function __construct($pdo)
{
$this->connection = new PDO("mysql:host=localhost;dbname=suggestotron", "root", "root");
$this->connection = $pdo;
}
}
?>
Expand All @@ -43,11 +43,11 @@ steps do
<?php
class TopicData {

protected $connection = null;
protected $connection;

public function connect()
public function __construct($pdo)
{
$this->connection = new PDO("mysql:host=localhost;dbname=suggestotron", "root", null);
$this->connection = $pdo;
}

public function getAllTopics()
Expand All @@ -70,10 +70,9 @@ steps do
source_code :php, <<-PHP
<?php
require 'TopicData.php';
$pdo = new PDO("mysql:host=localhost;dbname=suggestotron", "root", "root");

$data = new TopicData();
$data->connect();

$data = new TopicData($pdo);
$topics = $data->getAllTopics();
PHP

Expand Down