So I decided rather than putting it off any longer I'd try and separate my the business logic and display as suggested, this is what I've tried
<?php
class Database
{
private $host;
private $user;
private $pass;
private $dbname;
private $charset;
public function connect(){
$this->host = "localhost";
$this->user = "root";
$this->pass = "Testing1234";
$this->dbname = "menus";
$this->charset = "utf8mb4";
$dns = "mysql:host=".$this->host.";dbname=".$this->dbname.";charset=".$this->charset;
$pdo = new PDO($dns, $this->user, $this->pass);
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
return $pdo;
}
}
index
require('classCalls.php');
$test = new IndexPage();
$something = $test->drawIndex();
var_export($something);
class calls
<?php
spl_autoload_register(function ($class) {
include 'classes/' . $class . '.php';
});
IndexPage
<?php
class IndexPage extends Database{
function drawIndex(){
$sql = "SELECT * FROM restaurants";
$stmt = $this->connect()->query($sql);
while($row = $stmt->fetch()){
echo $row['name']; //for testing
}
}
}