我使用Myslq1作为我的Mysql数据库的连接插件,但是连接看起来没有问题,为何没有数据返回呢?请高手帮忙看一下,谢谢。
import 'package:mysql1/mysql1.dart' as mysql;
Future Database() async {
var settings = mysql.ConnectionSettings(
host: '108...',
port: 3306,
user: 'root',
password: '*****',
useSSL: false,
useCompression: false,
// maxPacketSize: 10000000,
//characterSet: utf8,
timeout: const Duration(seconds: 5000),
db: 'testdb');
var conn = await mysql.MySqlConnection.connect(settings);
print(conn.toString());
var result = await conn.query("SELECT * FROM users LIMIT 100;");
//await conn.close();
if (result.isEmpty) {
print('No data');
} else {
print(result.toString());
}
await conn.close();
}
运行结果:
[Running] dart "d:\Project\Flutter\e_shop\lib\service\service_method.dart"
lib/service/service_method.dart: Warning: Interpreting this as package URI, 'package:e_shop/service/service_method.dart'.
Instance of 'MySqlConnection'
No data
[Done] exited with code=0 in 2.066 seconds