= PHP =
The 825gen2 includes PHP which combined with the Apache Web Server allows for powerful web features.
{{{
card825gen2:~$ php -v
PHP 8.1.10 (cli) (built: Aug 30 2022 16:09:36) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.10, Copyright (c) Zend Technologies
}}}
Accessing MySQL database from php:
Make sure MySQL is configured first. Refer to the [wiki:Docs/825gen2/Dev/Database/MySQL MySQL] page
MySQL (MariaDB)
Create a simple test php file to read from the database
{{{
cd /usr/share/apache2/default-site/htdocs
nano readmysql.php
}}}
{{{
825 MySQL Test
query($sql);
if($result->num_rows > 0) {
echo 'Title | Description |
';
while($row = $result->fetch_assoc()) {
$title = $row['title'];
$description = $row['description'];
echo '' . $title . ' | ' . $description . ' |
';
}
echo '
';
}
}
?>
}}}
Test with PC on same network as 825.
[[Image(825webpagephp.png)]]
It may also be helpful to use browser "Developer tools" selection to view the generated html code.
[[Image(825webdevtools.png)]]
PHP can also be used to read SQLite databases.
{{{
card825gen2:/usr/share/apache2/default-site/htdocs$ cat testsqlite.php
825 SQLite Test
query('SELECT truck_name,tare FROM trucks');
echo 'Truck ID | Tare |
';
while ($row = $results->fetchArray()) {
$truckid = $row['truck_name'];
$tare = $row['tare'];
echo '' . $truckid . ' | ' . $tare . ' |
';
}
echo '
';
?>
}}}
[[Image(825webphpsqlite.png)]]
Following is a more advanced demo. This reads from an ID storage transaction table and also displays vehicle images associated with transactions.
ids.php
{{{
825 ID Storage
query($sql);
if($result->num_rows > 0) {
echo 'Tran Num | date/time | Vehicle Product Customer | Gross Wt | Tare Wt | Net Wt | Image | First pass |
';
while($row = $result->fetch_assoc()) {
$tkt_num = $row['tkt_num'];
$datetime = $row['date'] . ' ' . $row['time'];
$veh = $row['truck'];
$prod = $row['prod'];
$cust = $row['cust'];
$job = $row['job'];
$gross = $row['gross'];
$tare = $row['tare'];
$net = $row['net'];
echo '' . $tkt_num . ' | ' . $datetime . ' | ' . $veh . ' ' . $prod . ' ' . $cust . ' | ' . $gross . ' | ' . $tare . ' | '. $net . ' | ';
$imgfile = sprintf("v%06d_1.jpg", $tkt_num);
$img = 'images/' . $imgfile;
if(file_exists($img)) {
echo ' | ';
} else {
echo ' | ';
}
$imgfile = sprintf("v%06da_1.jpg", $tkt_num);
$img = 'images/' . $imgfile;
if(file_exists($img)) {
echo ' | ';
} else {
echo ' | ';
}
echo '
';
}
echo '
';
}
}
?>
}}}
[[Image(825webpage_ids_captured_images.png)]]