I created two PHP files on my website. First, I created a connection.php page which contains the database connection parameters (host/server, username, password, and database name). The connection.php uses MachForm's config.php to capture the database parameters from the defined constants. In the connection.php, I use the parameters to create the PDO connection object to access the database.
Then, I created a second PHP page to viewEntries.php to submit a query to the database to get the listing of all fields of interest for a specific form. This is a view-only page to review submitted data and no data is able to be edited or inserted (which is the desired presentation for specific users of this webpage).
//connection.php
<?php
require('config.php'); //Get access to defined database constants.
function OpenConn()
{
$dbhost = MF_DB_NAME;
$dbuser = MF_DB_USER;
$dbpass = MF_DB_PASSWORD;
$db = MF_DB_HOST;
$conn = new mysqli($dbhost, $dbuser, $dbpass, $db) or die("Connect failed: %s\n". $conn -> error);
return $conn;
}
function CloseConn($conn)
{
$conn -> close();
}
?>
// viewEntries.php
<?php
require('connection.php'); //Get access to defined database constants and the connection objection.
OpenConn();
echo "Connection successful!";
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT id
, date_created
, date_updated
, status
, edit_key
, element_2
, element_3
, element_4
, element_5_1
, element_5_2
, element_5_3
, element_5_4
, element_5_5
, element_5_6
, element_7_1
, element_7_2
, element_8
FROM xx_form_99999
";
//Format the data for display - could be a table or other useful formatting
print "Family:<br>";
foreach ($conn->query($sql) as $row) {
print $row['element_5_1'] . $row['element_5_2'] . "<br>";
CloseConn();
?>