简体   繁体   English

在没有node.js的情况下在JavaScript服务器端连接到MySQL

[英]Connect to MySQL in javascript server side without node.js

I have a javascript application running with server like nginx or eclipse local server , and i would like to know if it is possible to connect it with mysql server database. 我有一个与服务器(如nginxeclipse local server一起运行的javascript应用程序,我想知道是否可以将其与mysql服务器数据库连接。

I know that they are a lot of npm packages for nodejs application, but i don't want to use node js because if i'll do that i have to implement all structure of nodejs application with all dependencies and i don't know very well this technology to do that. 我知道他们有很多用于nodejs应用程序的npm packages ,但是我不想使用node js,因为如果这样做,我必须实现具有所有依赖项的nodejs应用程序的所有结构,我也不是很清楚好技术可以做到这一点。

Thanks. 谢谢。

There is no way to connect to a remote database server directly from JavaScript running in a browser… and if there was it would probably involve a huge security hole since anyone with access to the client could take your credentials and run any SQL they like on the server. 无法通过运行在浏览器中的JavaScript直接连接到远程数据库服务器……如果存在的话,这可能会带来巨大的安全漏洞,因为任何有权访问客户端的人都可以获取您的凭据并在其上运行他们喜欢的任何SQL。服务器。 It is unlikely you could make your database GRANTS fine-grained enough for public consumption. 您不太可能使数据库GRANTS具有足够的细粒度以供公众使用。

If you want your client side JS to interact with your database server then you need to write a webservice for it. 如果要让客户端JS与数据库服务器交互,则需要为其编写Web服务。 You can do that in Node.JS or any other server side environment you like. 您可以在Node.JS或您喜欢的任何其他服务器端环境中执行此操作。

If you are using Node.JS then you will probably want Nginx to proxy the requests. 如果您使用的是Node.JS,那么您可能希望Nginx 代理请求。

Nginx supports FastCGI so you could write in any language that supports FastCGI such as Perl or PHP . Nginx支持FastCGI,因此您可以使用任何支持FastCGI的语言(例如PerlPHP)进行编写

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM