Diary.db: Difference between revisions

1,729 bytes added ,  13:40, 4 April 2021
m
mNo edit summary
Line 21: Line 21:
*Snow depth (unsigned decimal number)
*Snow depth (unsigned decimal number)
*Entry (a text field for storing comments)
*Entry (a text field for storing comments)
== Accessing MX diary outside MX ==
The weather diary is stored in [[diary.db|a sqLite database]] and that can be easily accessed by any ODBC software e.g. Libre Office Base. It can also be accessed using PDO instructions in PHP Hypertext Preprocessor.
Here is an example in a PHP 7.3 (please note, this script will not work without changes for PHP 7.4, and PHP 8.x) script (modification of script available in [[File:Snow diary.zip]]) of accessing any one day ($rowMetDayStamp in yyyy-mm-dd format):
<pre>$diary = 'sqlite:' . $snowDiary; // Parameter to identify a SQLite database puts a prefix in front of file path
$dbhandle = new PDO($diary);  // connect to db
if($dbhandle === false)
{
$liteError = sqlite_last_error ($dbhandle );
echo ' Error: ' . sqlite_error_string ($liteError);
}else{
if($debug) echo $lf . '============================' . $lf . 'Success, database ' . $diary . ' is open' . $lf;
$queryRead =  "SELECT ALL *  FROM " . "'DiaryData'";
$statement = $dbhandle -> query($queryRead);
if($statement === false)
{
$liteError = sqlite_last_error ($dbhandle );
echo ' Error: ' . sqlite_error_string ($liteError);
}else{
$jump = false;
foreach ($statement as $row)
{
foreach($row as $key => $value )
{
if($key == 'Timestamp')
{
$keyDate = substr($value, 0, 10);
}
if($keyDate != $rowMetDayStamp) break;
if($key == 'snowFalling') $falling = $value;
if($key == 'snowLying') $lying = $value;
if($key == 'snowDepth') $depth = $value;
if($key == 'entry') $Entry = $value;
$jump = true;
        }
        if($jump)
{
$snowKnown = true;
goto snowDone;
}
}
}
}
</pre>
[[Category:Log Files]]
[[Category:Cumulus MX]]
5,838

edits