getting data from arduino to a database(mysql or any) - php

I would like your help on these. Does anyone know how to get data from arduino to a database? Specifically mysql or any other database that we can use.

You need a backend on your server. The Arduino calls a php script with POST or GET Parameters and the php script writes the content to your database.
Add some HTTP Basic Auth and the job is done,

Related

Simultaneous database query causing database error max_user_connections

I'm trying to import the excel data to mysql database by PHP Ajax method. When the user upload an excel, the jQuery will fetch each row by loop and send it to PHP via ajax but there are about 500++ rows. Due to that, the PHP is running the query simultaneously and causing the database error already has more than 'max_user_connections' active connections. Some of the query are working but some not.
the jQuery will fetch each row by loop and send it to PHP via ajax
...this is a design flaw. If you try to generate 500 AJAX requests in a short space of time it's inevitable, due to its asynchronous nature, that a lot of them will overlap and overload the server and database...but I think you've realised that already, from your description.
So you didn't really ask a question, but are you just looking for alternative implementation options?
It would make more sense to either
just upload the whole file as-is and let the server-side code process it.
Or
If you must read it on the client-side, you should at least send all the rows in one AJAX request (e.g. as a JSON array or something).

How can I get my javascript gererated data from the client to the server via PHP

A while back I wrote a rather long javascript procedure for organizing data we receive at work. The user simply paste in the mess we get and script throws out all the worthless info and generates a nice cleaned up data table.
I would like to add the ability to then transfer the processed information to the mySQL database. I'm growing a bit more comfortable using javascript, but I don't have close to the time or know-how to recreate the long processing procedure in PHP. How should I prep the data in javascript to most efficiently hand off the data to the server and have PHP insert it into mySQL tables?
The less PHP server side the better, although I doubt it would be safe to have a PHP page that blindly followed any instructions a referring page might send it.
At this point the data my script presents in the browser looks a lot like mySQL records already.
ex.
(Wilson, Paul, 1000400, A399)
(Smalls, Kalah, 4993944, B11)
(Chase, Danny, 244422, B133)
(Larson, Jay, 3948489, J39)
...
Thanks!
If you could have the data in a JSON array.
Then on the php side use json_decode to pull the data in as an array loop through it and do your updates and inserts for your data in MySQL.
http://php.net/manual/en/book.json.php

Dynamic MySQL commands through Javascript

Does anyone know of a Javascript + MySQL script that will allow me to dynamically request mysql information through javascript instead of having to make a seperate php file for each individual Ajax request i have?
I ask since I made a dynamic script that will insert MySQL info, and was curious if there was already one out there that can request it.
I hear that this idea could cause a security problem. Any ideas how to still make this possible? I have many AJAX requests and I don't want to make tens if not hundreds small PHP scripts for this...
Thanks!
I found the answer! By using hashes. I can simply add an md5 to the ajax (the md5 will contain the string info + some random code, this will be created using a php script). Then the script that actually inserts or requests the info from the database (php) will attempt to create the same md5 hash. If it is successfull, it is legit, if not, then stop the database request or post.
http://www.ajaxprojects.com/ajax/tutorialdetails.php?itemid=391

Getting big amount of data from a very slow external data-source

I need to recieve a big amount of data from external source. The problem is that external source sends data very slow. The workflow is like this:
The user initiates some process from app interface (common it is fetching data from local xml file). This is quite fast process.
After that we need to load information connected with fetched data from external source(basically it is external statistics for data from xml). And it is very slow. But user needs this additional inforamtion to continue work. For example he may perform filtering according to external data or something else.
So, we need to do it asynchronously. The main idea is to shows external data as it becomes available. The question is how could we organise this async process? Maybe some quess or something else? We`re using php+mysql as backend and jquery at front-end.
Thanks a lot!
Your two possible strategies are:
Do the streaming on the backend, using a PHP script that curls the large external resource into a database or memcache, and responds to period requests for new data by flushing that db row or cache into the response.
Do the streaming on the frontend, using a cross-browser JavaScript technique explained in this answer. In Gecko and WebKit, the XmlHttpRequest.onreadystatechange event fires every time new data is received, making it possible to stream data slowly into the JavaScript runtime. In IE, you need to use an iframe workaround, also explained at Ajax Patterns article linked in the above SO post.
One possible solution would be to make the cURL call using system() with the output being redirected in a file. Thus PHP would not hang until the call is finished. From the PHP manual for system():
If a program is started with this function, in order for it to continue running in the background, the output of the program must be redirected to a file or another output stream. Failing to do so will cause PHP to hang until the execution of the program ends.
This would split the data gathering from the user interface. You could then work with the gathered local data by several means, for example:
employ an iFrame in the GUI that would refresh itself in some intervals and fetch data from the local stored file (and possibly store it in the database or whatever),
use jQuery to make AJAX calls to get the data and manipulate it,
use some CGI script that would run in the background and handle the database writes too and display the data using one of the above from the DB directly,
dozens more I can't think of now...

update mysql detabase by using ajax

how we can update mysql detabase by using ajax...
any help or consept..
Ajax will have to call a remote script which will have to take care of the databse interaction. The code depends on the script language your database handling script will be written in.
You may have a look here for an example of ajax and mysql interaction.
You need to call a url from javascript, and do the job serverside.
We cannot update mysql database by using ajax!
Thus, divide your task into 2 parts:
make ordinal php script that updates a database by usual POST request.
debug it and make it to work
make AXAX code to make such a request.
debug it and make it to work
this way you can get your application working

Categories