How to connect mysql Database with Dart?

后端 未结 4 1205
滥情空心
滥情空心 2020-12-16 15:50

Does anyone can tell me how to connect to mysql database with Dart? I\'ve been reading and searching for days but can\'t find any suitable answers. I just learning web progr

4条回答
  •  無奈伤痛
    2020-12-16 16:13

    You can use SQLJocky to connect to MySQL. Add

    dependencies:
      sqljocky: 0.0.4
    

    to your pubspec.yaml an run pub install. Now you can connect to MySQL like this

    var cnx = new Connection();
    cnx.connect(username, password, dbName, port, hostname).then((nothing) {
        // Do something with the connection
        cnx.query("show tables").then((Results results) {
        print("tables");
        for (List row in results) {
          print(row);
        }
      });
    });
    

提交回复
热议问题