sqlbase 0.0.6
sqlbase: ^0.0.6 copied to clipboard
Dart to php to Sql database
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.4^ # Replace with the latest version
Then run:
flutter pub get
βοΈ Setup Guide #
1. Download the PHP Script #
Link - https://github.com/amazingsammed/sqlbase/blob/master/asset/sqlbase.php
π Download the PHP Script
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 = 'YourAddress';
$dbname = 'YourDatabaseName';
$username = 'YourUsername';
$password = 'YourPassword';
// API key must match the one used in your Flutter app
$apiKey = '123456';
4. Initialize the Plugin in Flutter #
Sqlbase.initialize(url: "http://localhost/sqlbase.php", key: '123456');
π Usage Guide #
Initialize #
Sqlbase.initialize(url: "http://localhost/sqlbase.php", key: '123456');
final myDB = Sqlbase();
π Read Data #
await myDB.table("users").get();
//OR
await SqlBase.select([]).from(tablename).execute();
β Insert Data #
await myDB.table("users").add({
"name": "Flutter",
"year": 2015,
});
// OR
await SqlBase.insertInto(tablename).values({
"name":"Sammed"
}).execute();
βοΈ Update Data #
await myDB.table("users").record("1", column: "id").update({
"name": "Next.js",
"year": 2019,
});
// or
await Sqlbase.update('user').where('id', '1').set({
"name": "Sammed"
}).execute();
β Delete Data #
await myDB.table("users").record("1", column: "id").delete();
// or
await Sqlbase.deleteFrom('user').where('id', '1').execute();
π§° 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
- Validate all user inputs to prevent SQL injection
- 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();
π§ͺ Testing #
To test locally:
- Use a tool like Postman to verify the PHP script response
- Check database connection and permissions
- Enable PHP error display for debugging:
ini_set('display_errors', 1); error_reporting(E_ALL);
π€ 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.