Included it and it just shows nothing, just breaking the form at the point where it shows the dropdown menu, consisting of no options.
I included the catch PDOException for the connection code line and it works now, but I have no idea why - the catch PDOException is just for error reporting, isn't it?
So now I have:
<select name="subject">
<?php
try {
$pdo = new PDO($dsn, $user, $pw);
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
try
{
/*** query the database ***/
$result = $pdo->query("SELECT subject_id, subject FROM subjects");
/*** loop over the results ***/
foreach($result as $row)
{
/*** create the options ***/
echo '<option value="'.$row['subject_id'].'"';
echo '>'. $row['subject'] . '</option>'."\n";
}
}
catch(PDOException $e)
{
echo 'No Results';
}
?>
</select>
Do I always have to include the catch PDOException to make the connection work? I am used to just do the connection code line as it was the case with mysql (mysql_connect etc.).
Greetings,
Frank