This is something I have running, so maybe it will shed some light on a method for you:
This is the code in the arduino which retrieves a table (I generate updates to the table elsewhere) from mysql and populates an array with the information:
void dbcpreadstats() {
String result; //creates a result string
char c; //creats a char
Process readstats; //
readstats.begin("php-cli");
readstats.addParameter("/mnt/sda1/db_cpreadstats.php");
readstats.run();
for (int d = 0; d < 15; d++) {
result = "";
c = 1;
while (readstats.available() > 0 && c != '\n') {
c = readstats.read();
if (isDigit(c)) result += c;
}
avgarray[d] = result.toInt();
}
}
This is the php script which simply selects a table and prints each line back to the arduino.
#!/usr/bin/php-cli
<?php
$DBServer = '127.0.0.1';
$DBUser = 'root';
$DBPass = 'xxxxxxxxxxxxxx';
$DBName = 'yun';
$conn = new mysqli($DBServer, $DBUser, $DBPass, $DBName);
// check connection
if ($conn->connect_error) {
trigger_error('Database connection failed: ' . $conn->connect_error, E_USER_ERROR);
}
$query = "SELECT data FROM assy5cp_stats;";
$result = $conn->query($query);
if($result === false) {
trigger_error('Wrong SQL: ' . $query . ' Error: ' . $conn->error, E_USER_ERROR);
}
$result->data_seek(0);
while ($row = mysqli_fetch_row($result)) {
printf ("%s \n", $row[0]);
}
$result->free();
$conn->close();
?>
I'm have added these packages:
php5
php5-cli
php5-mod-mysqli
I happen to be running the mysql server locally on the arduino with mysql-server, but there is no reason you would have to.
You can pass variables to the php script by adding a parameter to the process and then assigning a variable name to each argument in the php script:
$var1 = $argv[1]; //runid
$var2 = $argv[2]; //stage
$var3 = $argv[3]; //thermostat
$var4 = $argv[4]; //continuity
Your query would then look like this:
INSERT INTO ovenshifter_data (runid, stage, thermostat, continuity) VALUES ($var1,$var2,$var3,$var4);
I'm not a php expert at all, so I'm of little use actually troubleshooting your code.