Notes About Working with Various Arduino & Netduino Microcontroller Boards

Monday, October 28, 2013

Displaying Sqlite3 Data Using PHP on the Arduino Yun

I posted previously about using Sqlite3 as the database on an Arduino Yun for verifying RFID tag IDs and logging access. The example below shows how to use PHP to read from the access table and display the access data in a Web page.

See this post for information on installing PHP on the Arduino Yun.

Installing the PHP Sqlite3 Module

The first step is to install the PHP Sqlite3 module.  Run the following command at the Linux command line (logged in via SSH).

opkg install php5-mod-sqlite3

PHP Code

Use vim or nano at the command prompt to create the PHP file (access.php) in the /mnt/sd/arduino/www directory.

$db = new SQLite3('/mnt/sda1/rfid.db', 0666, $error)
        or die ($error);
$get_log_sql = <<<END_SQL
select a.date_time,, c.card
from rfid_access a, rfid_card c
where a.card = c.card
order by date_time desc
$result = $db->query($get_log_sql);
echo "<table cellpadding='5'>\n";
echo "<tr><th>Date & Time</th><th>Name</th><th>Card</th></tr>\n";
while ($row = $result->fetchArray()) {
        echo "<tr>";
        echo "<td>".$row['date_time']."</td>";
        echo "<td>".$row['name']."</td>";
        echo "<td>".$row['card']."</td>";
        echo "</tr>\n";
echo "</tr>\n";


Access the page by going to http://<YourYunAddr>/sd/access.php.

No comments:

Post a Comment