Connecting MySQL database in dart is really easy. First you have to create a dart project.
Plugin
mysql1: ^0.20.0
This plugin has some issues, but it's something that we have right now to work with.
Description
Create a function add host which in this case is localhost and port which your MySQL port is running.
In case of Windows you need XAMPP and in case of macOS see the documentation.
db is database name you created inside MySQL. Or You can add it by your own choice if you don't want to choose the existing one.
Writing queries inside function
Note
When you are using this plugin, and you're adding the db name in connection setting if you are adding the same name it will give you error even if your data is getting insert inside the database of existing table but one thing you should remember that db name should be different because db represent the database name and table is that will be generated inside the database. One thing also that you should not write insert query again and again to insert multiple data. Just use the same query and change data inside, it will insert on top of it with different ID of course. And at the end, don't forget to close it.
Top comments (0)