sqlbase 0.1.0 copy "sqlbase: ^0.1.0" to clipboard
sqlbase: ^0.1.0 copied to clipboard

SQLBase is a lightweight Flutter plugin that enables seamless communication between a Flutter app and an SQL database through a simple PHP back-end

SQLbase #

SQLbase is a lightweight Flutter plugin that enables seamless communication between a Flutter app and an SQL database through a simple PHP backend. It’s designed to function similarly to Firebase queries, making it easy and intuitive to use.

πŸš€ Features #

  • Connects Flutter with MySQL using PHP
  • Easy query interface inspired by Firebase
  • Lightweight and easy to integrate
  • Supports CRUD operations (Create, Read, Update, Delete)
  • Supports advanced SQL features like filtering, ordering, and grouping

πŸ“¦ Installation #

Add sqlbase to your pubspec.yaml file:

dependencies:
  sqlbase: 0.0.8^ # Replace with the latest version

Then run:

flutter pub get

βš™οΈ Setup Guide #

1. Download the PHP Script #

Old script #

Link - https://github.com/amazingsammed/sqlbase/blob/master/asset/sqlbase.php

New script #

Link - https://github.com/amazingsammed/sqlbase/blob/master/asset/sqlbase2.php

2. Deploy the Script #

Place the downloaded PHP file in your server’s root directory:

  • For WAMP, place it in the www/ folder
  • For other servers, use the respective public folder

3. Configure the PHP Script #

Open the script and set your database configuration:

$host = 'Your_Address';
$dbname = 'Your_Database_Name';
$username = 'Your_Username';
$password = 'Your_Password';

// API key must match the one used in your Flutter app
$apiKey = '123456';

πŸ“˜ Usage Guide #

Initialize #

final Sqlbase.initialize(url: "http://localhost/sqlbase.php", key: '123456');
final myDB = Sqlbase();

///  Read Data
await myDB.table("users").get();

///  Insert Data
await myDB.table("users").add({
  "name": "Flutter",
  "year": 2015,
});

///  Update Data
await myDB.table("users").record("1", column: "id").update({
  "name": "Next.js",
  "year": 2019,
});

///  Delete Data
await myDB.table("users").record("1", column: "id").delete();

Potential errors that can occur #

  • Contact The Developer: Error Key
  • Solution is to change the Authorization key in the php to start with capital A
/// change from
if (!isset($header['authorization']) || str_replace("Bearer ", "", $header['authorization']) !== $accessToken) {
    die(json_encode(['error' => 'Contact The Developer: Error Key']));
}


if (!isset($header['Authorization']) || str_replace("Bearer ", "", $header['Authorization']) !== $accessToken) {
    die(json_encode(['error' => 'Contact The Developer: Error Key']));
}

Database Methods #

  • .table("column")
  • .select([])
  • .insertInto("tablename")
  • .deleteFrom("tablename")
  • .auth("tablename")

Table Methods #

  • .where("column", isEqualTo: "value")
  • .isEqualTo({"column": "value"})
  • .limit(10)
  • .orderBy("column", "ASC" or "DESC")
  • .groupBy("column")
  • .get()
  • .add(Map<String, dynamic> data)
  • .addMany(List<Map<String, dynamic>> dataList)

Record Methods #

  • .update(Map<String, dynamic> newData)
  • .delete()

Best Practices #

  • Ensure the API key in your PHP file and Flutter app match
  • Use HTTPS in production for secure communication
  • Use environment variables or a secure config file for DB credentials

Examples #

// Read with condition
await myDB.table("products").where("price", isEqualTo: 100).get();

// Group and order
await myDB.table("users").groupBy("gender").orderBy("id", "DESC").limit(5).get();

🀝 Contributing #

We welcome contributions! Feel free to fork the repo and submit pull requests.

πŸ”— GitHub: https://github.com/amazingsammed/sqlbase

πŸ“„ License #

MIT License. See LICENSE for details.

0
likes
80
points
25
downloads

Publisher

unverified uploader

Weekly Downloads

SQLBase is a lightweight Flutter plugin that enables seamless communication between a Flutter app and an SQL database through a simple PHP back-end

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, flutter_web_plugins, http, path, plugin_platform_interface, web

More

Packages that depend on sqlbase

Packages that implement sqlbase