βοΈ AppML β Using Google Cloud SQL with AppML: Build Cloud-Connected Web Apps Easily
π§² Introduction β Why Use Google Cloud SQL with AppML?
Google Cloud SQL is a fully managed, scalable, and secure relational database service that supports MySQL, PostgreSQL, and SQL Server. When combined with AppML, you can build full-stack, cloud-powered applications using just HTML, JSON models, and PHPβwith no JavaScript or heavy backend frameworks required.
π― In this tutorial, youβll learn:
- How to set up Google Cloud SQL for AppML
- How to connect AppML server scripts to your Cloud SQL instance
- How to securely fetch and update cloud-hosted data
- How to build real-time views with AppML and GCP
π§ Step 1: Set Up Google Cloud SQL (MySQL)
β Create a Cloud SQL Instance
- Go to Google Cloud Console.
- Navigate to SQL > Create Instance > MySQL.
- Set instance ID (e.g.,
appml-instance). - Choose root password, region, and database version.
- Click Create.
β Configure Public Access
- In Instance Settings, go to Connections.
- Under IP Networks, click Add Network.
- Add your server IP (or
0.0.0.0/0for testing, not recommended for production). - Save changes.
β Create Database and Table
CREATE DATABASE appml;
USE appml;
CREATE TABLE products (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
price DECIMAL(10,2),
stock INT
);
β Your Cloud SQL DB is now ready for AppML integration.
π οΈ Step 2: Prepare AppML Files
π models/products-model.json
{
"key": "id",
"table": "products",
"fields": [
{ "name": "name", "required": true },
{ "name": "price", "datatype": "number" },
{ "name": "stock", "datatype": "number" }
]
}
βοΈ Defines the structure for CRUD operations using AppML.
π products.php
<?php
include("appml.php");
$appml = new AppML();
$appml->model = "models/products-model.json";
$appml->run();
?>
βοΈ This script connects the model to the database and handles all AppML requests.
π Update appml.php for Cloud SQL Connection
$hostname = "YOUR_PUBLIC_IP"; // From Cloud SQL
$username = "root";
$password = "your_password";
$database = "appml";
$conn = new mysqli($hostname, $username, $password, $database);
β
Ensure the YOUR_PUBLIC_IP matches the Cloud SQL instanceβs public IP address.
π₯οΈ Step 3: Create the AppML HTML Page
<div
appml-model="models/products-model.json"
appml-data="https://yourdomain.com/products.php"
appml-message>
<h2>Live Product List</h2>
<p>{{name}} β ${{price}} ({{stock}} in stock)</p>
</div>
β AppML will now load and display product data live from your Cloud SQL database.
π‘οΈ Best Practices for Cloud SQL Integration
| Security Practice | Why Itβs Important |
|---|---|
| Use HTTPS endpoints | Protects data in transit |
| Whitelist IPs only as needed | Avoid open access |
| Store DB credentials securely | Never expose them in HTML |
| Rotate passwords regularly | Limits security risk |
| Enable automatic backups on GCP | Prevents data loss |
π Use Cases β Why AppML + Google Cloud SQL Works Great
| Use Case | Benefit of This Stack |
|---|---|
| Small business admin dashboards | Fast setup, zero JS, full DB access |
| Education management systems | Host students/grades in a centralized cloud DB |
| Inventory or product listings | Easy CRUD from cloud without full stack framework |
| Low-code internal tools | Use HTML + JSON models without writing SQL |
π Summary β Recap & Key Takeaways
AppML + Google Cloud SQL gives developers the ability to create secure, scalable, and low-code web applications that connect directly to cloud-hosted MySQL databases. With AppML handling frontend logic and GCP powering backend storage, you can launch dynamic apps with minimal overhead.
π Key Takeaways:
- Use Google Cloud SQL to host your MySQL DB securely in the cloud
- Point
appml-datato a PHP endpoint connected to Cloud SQL - Define your DB schema with AppML JSON model files
- Secure your database access with firewalls, HTTPS, and credentials
- Ideal for dashboards, CMS, inventory apps, and student portals
βοΈ Build dynamic cloud-connected applications with easeβno JavaScript or complex backend needed.
β FAQs β AppML with Google Cloud SQL
β Can AppML connect directly to Cloud SQL from HTML?
β No. You must use a backend script (PHP or ASP) to serve data from Cloud SQL.
β What cloud database types does AppML support?
β
AppML works with any SQL-compatible DB (MySQL, PostgreSQL, etc.) via backend PHP/ASP.
β Can I host AppML on Netlify and still connect to GCP?
β
Yes. Just make sure your backend script (e.g., products.php) is hosted on a server that can access your Cloud SQL instance.
β Does Google Cloud SQL support free tier usage?
β
Google offers a limited free tier for MySQL with usage quotasβideal for testing or learning.
β What if my Cloud SQL public IP changes?
β
Use a static IP address or Cloud SQL instance proxy to avoid disruptions.
Share Now :
