0

My teacher asked me the question: "Why are SQL queries not possible to perform in JavaScript" to test my knowledge, and I answered because JavaScript is run on the client-side whereas SQL will be running on a server. This answer wasn't correct to his opinion and now I was searching the web but couldn't find the right answer. Could someone clarify this for me?

Mizugorou
  • 7
  • 2
  • I think that there is no right or wrong in this, it all depends on the level of security you are looking for. There is much more risk for Sql Injection if the SQL query's are in JavaScript. This is officious what I think. – Alen.Toma May 26 '21 at 22:44
  • 1
    Who says you can't? [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) – Spectric May 26 '21 at 22:45
  • @Spectric I think the teacher asked the question as a diversion as in 'Why shouldn't you do it" (I'm not sure what he was thinking when he asked the question) – Mizugorou May 26 '21 at 22:46
  • @Mizugorou Probably because you expose the credentials of a user in the database, opening your site up to a load of vulnerabilities. – Spectric May 26 '21 at 22:51
  • Unless your teacher specifically said _"JavaScript in the browser"_, they're totally wrong. https://www.npmjs.com/search?q=database-client. Even if they did say _"in the browser"_, they're still wrong (see link above) – Phil May 27 '21 at 00:08
  • @Phil he never said in the browser, he just asked: why are sql queries not possible in JavaScript. – Mizugorou May 27 '21 at 19:02
  • As you can see by the multitude of JS based SQL database client libraries, it is totally possible – Phil May 27 '21 at 21:20

0 Answers0