是否可以直接从Javascript访问MySQL数据库 [英] Is it possible to access a MySQL database straight from Javascript

查看:1635
本文介绍了是否可以直接从Javascript访问MySQL数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法使用完全客户端Javascript访问MySql数据库,还是需要通过PHP或C#等服务器端语言?

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#?

谢谢

推荐答案

如果在浏览器中运行,Javascript无法访问MySQL数据库。首先,这是一个技术限制,因为Javascript无法传递任意协议(不,WebSockets不是解决方案)。请注意,作为服务器端和所有端口的Node.js是不同类型的javascript。

Javascript, if run in the browser, has no way of accessing a MySQL Database. For one, this is a technical limitation, because Javascript has no way of communicating arbitrary protocols (no, WebSockets are not the solution). Note that Node.js, being server side and all, is a "different kind of javascript".

然后存在安全问题。如果您的 javascript可以直接访问数据库,我可以自己轻松访问数据库。我将能够读取和操作相同的数据你的 javascript即可。安全方面称这是一场噩梦。这是一种委婉说法。

Then there is the security issue. If your javascript could access the database directly, I could easily access the database myself. I would be able to read and manipulate the same data your javascript can. Security-wise calling this a nightmare would be an euphemism.

你必须 - 并且想要 - 通过服务器端应用程序路由数据库访问。如果该应用程序是用PHP编写的,那么C#或汇编并不重要。使用Node.js,您甚至可以在服务器端使用Javascript。使用你感觉舒服的东西。

You'll have to - and WANT TO - route database access through a server side application. If that app is written in PHP, C# or Assembly doesn't really matter much. With Node.js you can even use Javascript on the server side. Use what you're comfortable with.

这篇关于是否可以直接从Javascript访问MySQL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆