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 Reference - Databases


The "database" Property

The "database" property defines a database as the data source. It has the following sub properties:

Element Description
"connection" The name of a database connection
"execute" Array of SQL statements to be executed before data retrieval (optional)
"keyfield" The key field for the main table (optional)
"maintable" The main table for this application (optional)
"orderby" A fixed SQL orderby clause for the application (optional)
"sql" The SQL statement for retrieving data

Data From a Database

This model fetches records containing Customer, City, and Country from a Customer table in an SQL database:

Example

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

Filter Restrictions

To allow users to filter data, you can add filter information to the model:

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

Sorting Restrictions

To allow users to sort data, you can add sort information to the model:

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

Update Restrictions

To allow users to update data, you can include update information in the model: 

Example

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

By default, AppML will let you filter, sort, or update data, only it is specified in the model.



Database Connections

Database connections are defined in appml_config.php:

appml_config.php

<?php echo("Access Forbidden");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"
    }
]
}

The configuration file can contain many database connections.


Creating Databases

Since AppML allows you to execute SQL statements before the application is started, you can use this to create a database if needed:

Model

{
"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)"
]
}}

Perfect for rapid prototyping!


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

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.