I found some sample code that basically uses SQL PDO and then outputs the data into a table. However, I’ve done this in the past (years ago, but don’t recall using this escape function.) I am having trouble finding what it is or its use on DuckDuckGo.
Is there a better way of doing this?
$connection = new PDO($dsn, $username, $password, $options);
$sql = "SELECT * FROM users";
$statement = $connection->prepare($sql);
$statement->execute();
$result = $statement->fetchAll();
<?php foreach ($result as $row) : ?>
<tr>
<td><?php echo escape($row["id"]); ?></td>
<td><?php echo escape($row["firstname"]); ?></td>
<td><?php echo escape($row["lastname"]); ?></td>
<td><?php echo escape($row["email"]); ?></td>
<td><?php echo escape($row["age"]); ?></td>
<td><?php echo escape($row["location"]); ?></td>
<td><?php echo escape($row["date"]); ?> </td>
</tr>
It works, don’t get me wrong, it’s just that I like to know what functions do so I can use them on my own without always having to rely on the tutorial code in the future.
I know from my experience with Java, and, to a lesser extent, C++. that there’s a structure called a map that has a key and a value. It almost looks like the escape function is being passed the key of “date”, “location”, etc, and echoing the value for that iteration.