User Tools

Site Tools


Meeting Notes: Sat 6th April 2019

We worked through some demos of how to connect to a database and pull out some data with PHP. Here is the code we used:

Note: This isn't functioning code. It was used as an example to talk through what was going on

ini_set('display_errors', 1);

$host = "localhost";
$username = "coding_user";
$password = "cheese";
$db_name = "coding"; 

$mysql_string = "mysql:host=$host;dbname=$db_name";

$db_connection = new PDO($mysql_string, $username, $password);

$sql = "select * from test_table order by surname desc";
$rs = $db_connection->query($sql);
$rows = $rs->fetchAll(PDO::FETCH_ASSOC);

echo "<ol>"; 
foreach($rows as $row) {
        echo "<li>";
        echo $row['surname'].", ".$row['forename'];
        echo " (".date("D jS M Y", strtotime($row['date_added']));
        echo ")";
        echo "</li>";
echo "</ol>";


2019-04-06.txt · Last modified: 2019/08/15 10:58 by nmckillop