I know that most people say, "OH! It's not possible, use php" or whatever... That would be a waste of my time. I don't want to hear that it's not possible.
I'm looking for anyway possible that I can access mysql using javascript. I don't care how much of a drawn out process it is or that it would take node.js.
Just give me a way to do it. Node.js or AJAX is something I'm willing to look into, but I'd rather just use javascript and nothing else.
I do know PHP, Node.js, and AJAX, so I'm not looking for an easy way out. I just want to find out how.
* edit *
I guess this would be more of what I am looking for:
Is there any other types of sql or some sort of database that is accessable by in browser javascript?
I know that most people say, "OH! It's not possible, use php" or whatever... That would be a waste of my time. I don't want to hear that it's not possible.
I'm looking for anyway possible that I can access mysql using javascript. I don't care how much of a drawn out process it is or that it would take node.js.
Just give me a way to do it. Node.js or AJAX is something I'm willing to look into, but I'd rather just use javascript and nothing else.
I do know PHP, Node.js, and AJAX, so I'm not looking for an easy way out. I just want to find out how.
* edit *
I guess this would be more of what I am looking for:
Is there any other types of sql or some sort of database that is accessable by in browser javascript?
Share Improve this question edited Apr 20, 2013 at 8:24 Tgwizman asked Oct 19, 2011 at 3:05 TgwizmanTgwizman 1,5482 gold badges19 silver badges34 bronze badges 6- 4 Disregarding the many other ments this post begs, you do know that Node.js and AJAX are JavaScript...yes? – JAAulde Commented Oct 19, 2011 at 3:09
- 2 Does your Javascript environment have access to a TCP socket? Are you able to run your database server listening on a public network interface? (I'm trying to figure out if this is a really clever or a really ignorant question.) – Kerrek SB Commented Oct 19, 2011 at 3:10
- 1 Javascript has to run inside a javascript engine. Node.js is such an engine. A web browser is a different kind of javascript engine. So when you say, "I'd rather just use javascript and nothing else", what exactly are you looking for? Something that runs the browser? – Lee Commented Oct 19, 2011 at 3:12
- 7 "I don't want to heard that it's not possible, but there must be a way." - wait, what? Are you trying to demonstrate a can-do attitude, or is this just another variation on "I deny your reality and substitute my own"? – nnnnnn Commented Oct 19, 2011 at 4:09
- 1 Are you aware that if you would connect directly to the database from JS, the password would be visible to all users? – Sebastian Nowak Commented Oct 19, 2011 at 12:01
3 Answers
Reset to default 2You should checkout https://mongolab./home They provide full access to a NoSQL database using JSON objects which are directly accessible with jQuery calls. I saw these guys at a Hackathon and ended up winning a prize! They are cool and will probably give you direct help if you click the support link.
Certainly possible. Web Application servers best suit that role, e.g. PHP, Cold Fusion, RubyOnRails, java(JSP), (ASP), etc.
You use javascript to send a request that the application server than uses to access the mysql server and... usually server up some of the results in a web page :)
To connect mysql using javascript, you can use the mysql package from npm.
npm i mysql
import mysql from "mysql";
var connection = mysql.createConnection({
host: "localhost",
user: "root",
password: "",
database: "social_media",
});
connection.connect();
const getUserById = (id) => {
connection.query(`SELECT * FROM users where id = ${id}`, function (err, results, fields) {
if (err) throw err;
console.log("The solution is: ", results);
});
};
getUserById(7);
connection.end();