3

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?

6
  • 4
    Disregarding the many other comments this post begs, you do know that Node.js and AJAX are JavaScript...yes? 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.) 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? 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"? 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? Commented Oct 19, 2011 at 12:01

3 Answers 3

2

You should checkout https://mongolab.com/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.

Sign up to request clarification or add additional context in comments.

Comments

2

Certainly possible. Web Application servers best suit that role, e.g. PHP, Cold Fusion, RubyOnRails, java(JSP), .net(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 :)

Comments

0

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();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.