I need to create a website which allows a user to create a job which is saved to a database and then all the jobs can be viewed from a different page on the website. I've managed to get this to work but I've had to duplicate all of the MySQL log in set up in PHP. I'd like to avoid this duplication and tried using an autoloader but with no success. Basically the first 5 variables are repeated from a separate page where I'm adding the data into the database and I'd like to avoid this if possible. The code itself works I just feel like there must be a way to avoid repetition here.
<?php
$server = '192.168.56.2';
$username = 'student';
$password = 'student';
$schema = 'assignment';
$pdo = new PDO('mysql:dbname=' . $schema . ';host=' . $server, $username, $password);
$file ='section3.php';
echo 'Last Edited: ' .date('d/m/Y', filemtime($file));
$results = $pdo->query('SELECT * FROM jobs');
foreach ($results as $row) {
echo '<p>' . $row['title']." " . $row['salary'] ." ". $row['location'] ." ". $row['description'].'</p>';
}
?>