DEV Community

Cover image for Connecting MySQL database in Dart
Ayoub Ali
Ayoub Ali

Posted on

2 1

Connecting MySQL database in Dart

Connecting MySQL database in dart is really easy. First you have to create a dart project.
Create 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.

Function

Writing queries inside function

Queries

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.

SourceCode

Sentry growth stunted Image

If you are wasting time trying to track down the cause of a crash, it’s time for a better solution. Get your crash rates to zero (or close to zero as possible) with less time and effort.

Try Sentry for more visibility into crashes, better workflow tools, and customizable alerts and reporting.

Switch Tools 🔁

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay