Can I store variable from Arduino directly to MySQL database?

I am working on a project using Arduino+Ethernet LAN shield to count something.
Then I would like to show the number in webpage, and also store the number to database.

Can I store that 'number' variable from Arduino directly to MySQL database using LAN Cable or Serial Cable?
If so, what I should prepare in MySQL? What command I should use?

Which one is better:

  1. Store variable from Arduino to Database then show it in webpage
    or
  2. Show variable from Arduino to Webpage then store it to Database?

Thank you very much.

DO NOT CROSS-POST.

Duplicate post removed.

creativen:
I am working on a project using Arduino+Ethernet LAN shield to count something.
Then I would like to show the number in webpage, and also store the number to database.

Can I store that 'number' variable from Arduino directly to MySQL database using LAN Cable or Serial Cable?
If so, what I should prepare in MySQL? What command I should use?

Which one is better:

  1. Store variable from Arduino to Database then show it in webpage
    or
  2. Show variable from Arduino to Webpage then store it to Database?

Thank you very much.

I'm doing something very similar - Based on what I've read so far (very little) I do not believe there is a library that can talk direct to MySQL simply. I write my value to a script (PHP) running on a webserver and validate that the values are correct in both value and source and then store it into the database. I've successfully posted just shy of 19,000 values to my webserver over the space of 5 days without issue during my testing so there is no bottle neck based on bandwidth of my home network.

Each time I submit a value it is always '1' to allow me to sum my values at a later date, in the event that there is no comms to the webserver I increment a local counter and the next time I may post '2' or maybe '22' depending on how long the loss of comms has occurred - I like to refer it to a basic store&forward solution.

So, the solution is first get the variable to webpage then store it to mysql.

PeteOC:
I write my value to a script (PHP) running on a webserver and validate that the values are correct in both value and source and then store it into the database. I've successfully posted just shy of 19,000 values to my webserver over the space of 5 days without issue during my testing so there is no bottle neck based on bandwidth of my home network.

what value?
webserver?do you mean WAMP?
what script I should type? where I should put it?
How do you retrieve the data from webpage to database? do you have step by step solution?

Thank youu.

see http://www.begerk.co.uk/general/latest-code/ for the Arduino code to post the data to a URL.

At the time of writing this code has posted 103431 data points to my web page.

The website is simple, assuming you know PHP? A WAMP server is suitable however I've got a self built LAMP server :slight_smile:

Based on your opening post I made the assumption that you know how to store data from a web page into MySQL and retrieve it, was my assumption wrong?

creativen:
I am working on a project using Arduino+Ethernet LAN shield to count something.
Then I would like to show the number in webpage, and also store the number to database.

Can I store that 'number' variable from Arduino directly to MySQL database using LAN Cable or Serial Cable?
If so, what I should prepare in MySQL? What command I should use?

Which one is better:

  1. Store variable from Arduino to Database then show it in webpage
    or
  2. Show variable from Arduino to Webpage then store it to Database?

Thank you very much.

What platform is the host that your Arduino is connected to?

If it is WIndows based, you can use Gobetwino to receive commands from the Arduino and execute a command on the host. The command would invoke an SQL command line client to run an SQL query that inserts your value into the database. With this approach, no programming is required other than a Serial.println on the Arduino to output each result.

Using Ethernet/HTTP/web server/PHP to access the database would work fine, of course, but take a bit more work.

What platform is the host that your Arduino is connected to?

If it is WIndows based, you can use Gobetwino to receive commands from the Arduino and execute a command on the host. The command would invoke an SQL command line client to run an SQL query that inserts your value into the database. With this approach, no programming is required other than a Serial.println on the Arduino to output each result.

Using Ethernet/HTTP/web server/PHP to access the database would work fine, of course, but take a bit more work.

Yes, it is Windows based.
Hmm Gobetwino, I would like to avoid using serial cable, but only using LAN Cable, so it is more effective if I can use Ethernet/HTTP/Web Server/PHP to access the database.
The reason I would like to use LAN Cable, due to effectiveness to share it to other computer using LAN Router.
What do you think?

Do you have any idea how to use php to access the database?

Thank you for response. :smiley:

If you have a LAN interface and prefer to use that then the HTTP/PHP based solution seems pretty straight forward. You do need to write the Arduino code to do the HTTP POST, and you have to create a web app (presumably PHP based) which writes the posted data to a database. That's a well-trodden path.