Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

AppML 参考 - 数据库


"database" 属性

"database" 属性将数据库定义为数据源。它具有以下子属性

元素 描述
"connection" 数据库连接的名称
"execute" 在数据检索之前要执行的 SQL 语句数组(可选)
"keyfield" 主表的键字段(可选)
"maintable" 此应用程序的主表(可选)
"orderby" 应用程序的固定 SQL orderby 子句(可选)
"sql" 检索数据的 SQL 语句

来自数据库的数据

此模型从 SQL 数据库中 Customer 表中获取包含 Customer、City 和 Country 的记录

示例

{
"database": {
    "connection": "mysql",
    "sql"       : "SELECT CustomerName, City, Country FROM Customers",
    "orderby"   : "CustomerName"
}
}

筛选限制

要允许用户筛选数据,您可以向模型添加筛选信息

"filteritems" : [
    {"item" : "CustomerName", "label" : "客户"},
    {"item" : "City"},
    {"item" : "Country"}]

排序限制

要允许用户排序数据,您可以向模型添加排序信息

"sortitems" : [
    {"item" : "CustomerName", "label" : "客户"},
    {"item" : "City"},
    {"item" : "Country"}]

更新限制

要允许用户更新数据,您可以在模型中包含更新信息:

示例

"updateItems" : [
    {"item" : "CustomerName"},
    {"item" : "Address"},
    {"item" : "PostalCode"},
    {"item" : "City"},
    {"item" : "Country"}]

默认情况下,AppML 仅允许您筛选、排序或更新模型中指定的数据。



数据库连接

数据库连接在 **appml_config.php** 中定义

appml_config.php

<?php echo("禁止访问");exit();?>
{
"dateformat" : "yyyy-mm-dd",
"databases": [
    {
    "connection" : "mysql",
    "host"       : "127.0.0.1:3306",
    "dbname"     : "Northwind",
    "username"   : "myUserId",
    "password"   : "myPassword"
    },
    {
    "connection" : "googleDB",
    "host"       : "192.168.1.1:3306",
    "dbname"     : "Northwind",
    "username"   : "myUserId",
    "password"   : "myPassword"
    },
    {
    "connection" : "amazonDB",
    "host"       : "mydbinstance.amazon.com:3306",
    "dbname"     : "Northwind",
    "username"   : "myUserId",
    "password"   : "myPassword"
    },
    {
    "connection" : "azureDB",
    "host"       : "azure.cloudapp.net",
    "dbname"     : "Northwind",
    "username"   : "myUserId",
    "password"   : "myPassword"
    }
]
}

配置文件可以包含多个数据库连接。


创建数据库

由于 AppML 允许您在应用程序启动之前执行 SQL 语句,因此您可以在需要时使用它来创建数据库

模型

{
"database" : {
"connection" : "myCDs",
"execute" : [
"DROP TABLE IF EXISTS CD_Catalog",
"CREATE TABLE IF NOT EXISTS CD_Catalog (CDID INT NOT NULL AUTO_INCREMENT,PRIMARY KEY (CDID),Title NVARCHAR(255),Artist NVARCHAR(255),Country NVARCHAR(255),Price NUMBER)"
]
}}

非常适合快速原型设计!


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.