hi
it's really quite easy to use a PHP script to communicate between MySQL and p5. no need to sign the applet or talk to tomcat unless you're sending too much data for a GET request (the maximum length of a URL for the server, which i think is by default about 2000 characters on iis/windows servers and about 8000 on apache/*nix servers).
i believe it's actually more secure to handle the databse stuff in a php script than in p5 because a java applet can potentially be decompiled and then your MySQL login/password/server is available to be borrowed/stolen/h4xx0red.
to talk to mysql through php, i just use loadStrings(url) where the String url has been composed of data i want to insert into the database.
for example:
Code:
String url = "http://domain.com/insert.php?color=" + theColor + "&size=" + theSize;
loadStrings(url);
that loadStrings() is just to get p5 to send the request; the script doesn't actually return any text to it.
the insert.php file will look something like this:
Code: // insert.php
<?PHP
$dblink = mysql_connect("mysqldatabase.domain.com", "mysql_username", "mysql_password");
mysql_select_db("name_of_database");
$color = $_GET['color];
$size = $_GET['size'];
$sql = "INSERT INTO squares SET size='$size' color='$color'";
$result = mysql_query($sql);
?>
then to read out all squares from the database, i'll have a script called 'read.php' or something that looks like this:
Code: // read.php
<?PHP
$dblink = mysql_connect("mysqldatabase.domain.com", "mysql_username", "mysql_password");
mysql_select_db("name_of_database");
$sql = "SELECT * FROM squares";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
echo $row['color'];
echo " || ";
echo $row['size'];
echo "\n";
}
?>
the output is easy to parse with p5's split().
keeping the database access logic on the server has the additional advantage that if you need to change your database structure or something you can do so without requiring users to download a new client.
hope this is helpful!
-jake