Is it possible to access a MySQL database straight from Javascript

前端 未结 6 1736
孤街浪徒
孤街浪徒 2020-11-30 15:23

Is there a way to access a MySql database using entirely client side Javascript or do you need to go through a server side language such as PHP or C#?

Thanks

6条回答
  •  野性不改
    2020-11-30 15:45

    Yes, you can use a Javascript library like Node.js to perform MySQL queries in Javascript - it's just a really bad idea (TM) to do this client side, as you'd need to send users the authentication details and provide the ability for clients to connect to your MySQL server, meaning it'd have to be internet accessible to any IP! Not good. However if you really wanted just because you prefer Javascript but you only intend to do it on the server, try: (What MySQL drivers are available for node.js?).

    What you should do is implement a small server-side script perhaps in PHP or Perl or Python or C#, which outputs just the data you want from the query and use AJAX to process the response.

提交回复
热议问题