在不使用 php 的情况下使用 JQuery 访问 Mysql

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2716346/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 14:08:00  来源:igfitidea点击:

Accessing Mysql with JQuery without using php

jquerymysql

提问by Miek

I'm very new to JQuery, but I was told the one of the cool things about it is you can query a mysql database right from an html page(or in my case a smarty template)with out needing php.

我对 JQuery 很陌生,但有人告诉我,其中一件很酷的事情是您可以直接从 html 页面(或在我的情况下是智能模板)查询 mysql 数据库,而无需 php。

I have not found any examples of this so I am asking if someone has one? Thanks

我还没有找到任何这样的例子,所以我问是否有人有这样的例子?谢谢

回答by spender

Let's hope that you continue not to find any examples of this. By necessity, DB access is kept away from the client. Imagine the mayhem if users could pop open your JS and start firing arbitrary queries/commands at your DB.

让我们希望您继续不要找到任何此类示例。必要时,数据库访问远离客户端。想象一下,如果用户可以打开您的 JS 并开始在您的数据库中触发任意查询/命令,那将会是多么混乱。

回答by SLaks

This is not possible.

这不可能。

You might be hearing about the HTML5 Web SQL Databasestandard.

您可能听说过HTML5 Web SQL 数据库标准。

回答by Pekka

Nope, you're misinformed. This is definitely not possible. You will always need a server-side language to access a remote database, JQuery is not built to do this.

不,你被误导了。这绝对是不可能的。您将始终需要一种服务器端语言来访问远程数据库,JQuery 不是为此而构建的。

JQuery is able to parse RSS feeds, JSON and XML documents without a server-side language (related questions e.g. hereand here). Maybe that is what you mean?

JQuery 能够在没有服务器端语言的情况下解析 RSS 提要、JSON 和 XML 文档(相关问题,例如这里这里)。也许这就是你的意思?

回答by Tgr

Even if that was possible (it is not), it would be a horrible idea, as the visitor can see and manipulate everything that happens in javascript, so he would get free access to your database.

即使这是可能的(不是),这也是一个可怕的想法,因为访问者可以查看和操作 JavaScript 中发生的所有事情,因此他可以免费访问您的数据库。

Some non-relational databases allow JSON queries, though.

不过,一些非关系数据库允许 JSON 查询。

回答by Nicholas Wilson

It is theoretically possible. You could write a simple MySql remote client in JS, and grant anonymous remote read-only access to certain parts of your database (like the content table, but not tables storing user data). It would be silly, but MySql does have direct remote access functionality. jQuery does not do this though, and trying it out would be a very silly idea, though it could be made sufficiently secure if you really wanted it.

理论上是可以的。您可以在 JS 中编写一个简单的 MySql 远程客户端,并授予匿名远程只读访问您数据库的某些部分(如内容表,但不是存储用户数据的表)。这很愚蠢,但 MySql 确实具有直接远程访问功能。但是 jQuery 不会这样做,尝试它是一个非常愚蠢的想法,尽管如果您真的想要它,它可以变得足够安全。

回答by Sarfraz

jQuery works client-side, you need a server-side language such as php, asp.net, etc to do that. Simply not possible with jQuery.

jQuery 在客户端运行,您需要一种服务器端语言,例如 php、asp.net 等来实现。jQuery 根本不可能。

回答by Amy B

You can't do that. To use a database, there needs to be something on the server that connects to the DB server and authenticates.

你不能那样做。要使用数据库,服务器上需要有一些东西可以连接到数据库服务器并进行身份验证。

PHP isn't necessarily needed. You could use Rails, Python, Java...

不一定需要 PHP。你可以使用 Rails、Python、Java……

回答by ceejayoz

Somesort of server-side interaction needs to be present.

有些种类的服务器端的交互需要存在。

Smarty's just a template language on top of PHP, so it's entirely possible to create a Smarty template that provides JavaScript-readable data (presumably, JSON or XML) for subsequent AJAX fetching via jQuery.

Smarty 只是 PHP 之上的一种模板语言,因此完全有可能创建一个 Smarty 模板,该模板提供 JavaScript 可读的数据(大概是 JSON 或 XML),以便通过 jQuery 进行后续的 AJAX 获取。

回答by Andrea

Maybe you are referring to the client-side database APIwhich is specified by HTML5.

也许您指的是 HTML5 指定的客户端数据库 API