1

I am trying to connect to a database using JavaScript. I have read that it is not recommended to use Client-side to connect to the database, for multiple reasons. But right now I am just trying to make a working local version.

What are some suggestions for getting a working local version? Am I able to get it done with purely JavaScript even tho it is bad practice? Or do I need assistance by php/ajax to make it work?

I have no experience with PHP.

3
  • Not only is it not recommended, but also it is impossible (that might be one of the "multiple reasons"). You physically can't connect to a database (necessarily hosted on a server) directly from a browser. Commented Sep 11, 2017 at 11:27
  • 1
    Use nodeJs to code javascript server side and set up a connection. Communicate between client and server using javascript. Commented Sep 11, 2017 at 11:30
  • 1
    Possible duplicate of How to connect to SQL Server database from JavaScript in the browser? Commented Sep 11, 2017 at 11:34

1 Answer 1

1

i thought it's impossible until i just saw this post.

but even if it is possible, don't do it! with this solution, every user can see the database connection parameters like username and pwd and therefore mess with your DB.

Instead, learn how to access a DB using PHP and use that in your local environment already. Its really not that complicated, you can find many instructions and tutorials if you're looking around

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

3 Comments

Thanks for actually showing that it is possible. While still advising against it.
why do i have the feeling that you are gonna try it out.. I can't stress this enough: don't do it :) anyway, there is a good chance that it won't work anymore since the post of my link is over 8 years old
Actually it was my boss that wanted me to do "bad practice" without php because i don't have experience with php. Now I am trying to make it work with php and xampp :)

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.