如何将 PhoneGap 移动应用程序连接到远程 MySQL 数据库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28917860/
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-31 13:23:17  来源:igfitidea点击:

How to connect a PhoneGap Mobile App to a remote MySQL Database

mysqldatabasecordovadreamweaver

提问by miss h

I am trying to build an application for ios and android using dreamweaver and then convert it to these OS using PhoneGap. I f there is an examples I can follow please provide me with these examples and tutorials. I found something related to using PHP, but I don't want to use PHP. Thank you. Hind

我正在尝试使用 Dreamweaver 为 ios 和 android 构建一个应用程序,然后使用 PhoneGap 将其转换为这些操作系统。如果有我可以遵循的示例,请向我提供这些示例和教程。我发现了一些与使用 PHP 相关的内容,但我不想使用 PHP。谢谢你。后

回答by Priyanka

For Connecting with MySQL Database, you need to create a web service using PHP for JSON-based output.

为了连接 MySQL 数据库,您需要使用 PHP 创建一个用于基于 JSON 的输出的 Web 服务。

  1. Create MySQL Database
  2. Create JSON Based Web Service using PHP / JSP / ASP whatever.
  3. Use Jquery / Angular JS for GET / POST data from the web service & display them on your PhoneGap application
  1. 创建 MySQL 数据库
  2. 使用 PHP/JSP/ASP 创建基于 JSON 的 Web 服务。
  3. 使用 Jquery/Angular JS 获取来自 Web 服务的 GET/POST 数据并将它们显示在您的 PhoneGap 应用程序上

Read this https://codesundar.com/phonegap-php-mysql-example/for performing CRUD operations

阅读此https://codesundar.com/phonegap-php-mysql-example/以执行 CRUD 操作

回答by Fiach Reid

Typically, you need a server side scripting language like PHP to connect to MySQL, however for closed-source Phonegap apps, you can use http://www.mysqljs.comto connect to MySQL from Javascript using code as follows:

通常,您需要像 PHP 这样的服务器端脚本语言来连接 MySQL,但是对于闭源 Phonegap 应用程序,您可以使用http://www.mysqljs.com使用以下代码从 Javascript 连接到 MySQL:

MySql.Execute(
    "mysql.yourhost.com", 
    "username", 
    "password", 
    "database", 
    "select * from Users", 
    function (data) {
        console.log(data)
});

It has to be mentioned that this is not suitable for website use, since the database access credentials are visible in the source code.

必须提到的是,这不适合网站使用,因为数据库访问凭据在源代码中是可见的。