I want to store data into mysql table using JavaScript. But, I don't want to use php. Is it possible?
6
-
See here: stackoverflow.com/questions/3020751/…Nikhil– Nikhil2017-05-03 06:13:56 +00:00Commented May 3, 2017 at 6:13
-
you might want to use node js that might help you interact with the server using java scriptRahul Singh– Rahul Singh2017-05-03 06:16:13 +00:00Commented May 3, 2017 at 6:16
-
You can use any language you want on the server side.Felix Kling– Felix Kling2017-05-03 06:19:09 +00:00Commented May 3, 2017 at 6:19
-
Just curious: why not php?Strawberry– Strawberry2017-05-03 07:11:40 +00:00Commented May 3, 2017 at 7:11
-
Possible duplicate of Can JavaScript connect with MySQL?mbdevpl– mbdevpl2017-05-03 08:24:50 +00:00Commented May 3, 2017 at 8:24
|
Show 1 more comment
3 Answers
Javascript is a client-side language, so it runs on the clients browser. If you still want to insert into mysql using javascript then you could use something like node.js which would run on the server-side.
For instance this is how an insert using node.js would look like:
var post = {id: 1, title: 'Hello MySQL'};
var query = connection.query('INSERT INTO posts SET ?', post, function(err, result) {
// check result or error!
});
3 Comments
Jahangir
actually I want to use it only for like counter, I mean i want to increment in like counter. I hope you might understand what I want to do .. further is it a good approach to use node.js for only like counter ?
lloiacono
@Jahangir what is it that you would like to count?
Jahangir
as I said above. I want to count "likes" of a video on my webpage.
1 Comment
Davinder Kumar
This is not the answer. It should be a comment
Jahangir jan, It's not possible to use client side Javascript to store something into the MySQL. But it's possible to use server side Javascript to do it.
1 Comment
Hossein
Yes nodejs is a server side Javascript language so you can communicate with database as well.