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.

Rainoa
  • 491
  • 1
  • 4
  • 14
  • 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. – Jeremy Thille Sep 11 '17 at 11:27
  • 1
    Use nodeJs to code javascript server side and set up a connection. Communicate between client and server using javascript. – Eladian Sep 11 '17 at 11:30
  • 1
    Possible duplicate of [How to connect to SQL Server database from JavaScript in the browser?](https://stackoverflow.com/questions/857670/how-to-connect-to-sql-server-database-from-javascript-in-the-browser) – Neodan Sep 11 '17 at 11:34

1 Answers1

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

kscherrer
  • 5,486
  • 2
  • 19
  • 59
  • Thanks for actually showing that it is possible. While still advising against it. – Rainoa Sep 13 '17 at 15:06
  • 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 – kscherrer Sep 13 '17 at 15:13
  • 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 :) – Rainoa Sep 13 '17 at 15:44