【问题标题】:How to use correct the MySQL nodejs modul in Appcelerator?如何在 Appcelerator 中正确使用 MySQL 节点 js 模块?
【发布时间】:2016-05-31 15:22:15
【问题描述】:

我使用三星 A5 在 Windows 8.1 下的 Appcelerator Studio 有几天了。现在我想使用 mysql nodejs 模块。我在网上阅读了将mysql副本的目录复制到我的资源目录下的内容。 所以,我的文件夹是这样的:

Projectname
+-- Resources
    +-- android
    +-- mysql
    |   +-- lib
    |   |   +--- ...
    |   +-- node_modules
    |   |   +--- ...
    |    \- index.js
     \- app.js

这是我的 app.js:

    var mysql = require('mysql');
    var connection = mysql.createConnection({
      host: 'domain',
      user: 'user',
      password: 'password',
      database: 'database'
    });

    connection.connect(function (err) {
        if (err) {
            alert("Error on mysql connect: " + err.stack);
            return;
        }
    });

    alert("Mysql connect is correct.");

    connection.end();

项目在三星上安装,但是启动时报错:mysql module is not found.

怎么了。 请帮帮我!

感谢您的帮助,对不起我的英语!

【问题讨论】:

  • 添加了关于 mysql 的“一般”答案,还添加了如何让 mysql 节点模块工作:)

标签: javascript android sqlite appcelerator appcelerator-titanium


【解决方案1】:

Titanium 中没有 iOS/Android 上的 MySQL 之类的东西。那里的数据库是 SQLite。您可以在documentation of Appcelerator 中阅读有关 SQLite 的信息。

它也不是一个模块,而是一个good old API。示例(来自文档)

var db = Ti.Database.open('TiBountyHunter');
db.execute('CREATE TABLE IF NOT EXISTS fugitives(id INTEGER PRIMARY KEY, name TEXT, captured INTEGER, url TEXT, capturedLat REAL, capturedLong REAL);');
db.close();

如果您有一个名为 mysql 的模块,则应将其放在 lib 文件夹中以使其工作。但是,如果它具有 Node 依赖项,这可能会很困难。然后你可以使用Titaniumifier

【讨论】:

  • 感谢 Rene 的回答! “mysql”是一个合法的 nodejs 模块。这是 URL:link 在 mysql 目录中有一个 index.js、一个“lib”和一个“node_modules”目录。我将 mysql 目录复制到 Resources/lib 目录,但它不起作用。
  • 您研究过 Titaniumfier 吗?钛不包含节点。您的 mysql 模块使用任何依赖项,它们也需要包含在内。
  • 所以,我不使用钛。我使用 Appcelerator Studio,这是识别我的 nodejs 并在帮助/首选项中配置。是的,我看到了 Titaniumfier,但我不知道如何使用它从我的 Android 应用程序连接到 MySQL 数据库。
  • Appcelerator Studio 基于 Eclipse 构建。 Appcelerator Studio 集成了构建 Titanium 应用程序的 Appcelerator CLI。是的,你使用钛。不,应用程序本身不涉及节点,仅在构建期间。 Titanium 应用程序中根本没有 MySQL,什么都没有。因此,除非您能够以某种方式在应用程序中安装 MySQL/远程连接到数据库,否则这将不起作用,您必须使用 SQLite。因此,我的答案开始了
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-31
  • 2021-10-10
相关资源
最近更新 更多