OK, I finally found some time to experiment. I wanted to try SQL connection with Processing, so it was a good opportunity.
First, I created a test table in the default test base of my local MySQL base:
Code:CREATE TABLE p5_messages
(
id int(11) NOT NULL auto_increment,
creator varchar(32) default NULL,
message varchar(160) default NULL,
date_added datetime default NULL,
PRIMARY KEY (id)
) ENGINE=MyISAM CHARSET=latin1;
Then I wrote a little PHP script to enter data there:
Code:<body>
<h1>Filling Database Fields</h1>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<fieldset><legend>Message Input</legend>
<label for="author">Author:</label><input type="text" name="author" id="author"/><br/>
<label for="message">Message:</label><input type="text" name="message" id="message" size="160"/><br/>
<input type="submit"/>
</fieldset>
</form>
</body>
</html>
<?php
if (!isset($_POST['message']))
return; // Just display the page
$author = htmlspecialchars(@$_POST['author']);
$message = htmlspecialchars(@$_POST['message']);
AddData($author, $message);
?>
<?php
function AddData($author, $message)
{
$cnx = mysql_connect('localhost', 'PhiLho', 'Foo#Bar') or die('Could not connect: ' . mysql_error());
mysql_select_db('tests', $cnx) or die('Could not select DB "tests": ' . mysql_error());
mysql_query("INSERT INTO p5_messages (creator, message, date_added)
VALUES ('$author', '$message', now())");
mysql_close($cnx);
}
?>
And finally I wrote a sketch to display this data.
I had some difficulty to find a good strategy so each message is displayed a minimum time, even if there are bursts of new messages.
Mmm, the latter code is a bit long, continuing on next message.