您好,我是 Flutter 的新手,我正在尝试根据用户输入的关键字从 MYSQL 数据库中获取数据。但即使数据存在,结果也是空的。我正在使用 msqljocky5 包进行 MYSQL 连接。
Future<Results> getProducts()async{
if(searchValue==""){
ConnectionSettings settings = new ConnectionSettings(
host: '10.0.2.2',
port: 3306,
user: 'root',
password:'',
db: 'master'
);
dynamic db = await MySqlConnection.connect(settings);
try{
Results results = await (await db
.execute('SELECT * from product'))
.deStream();
await db.close();
return (results);
}catch(e){
print("Error01"+e.toString());
}
}else{
ConnectionSettings settings = new ConnectionSettings(
host: '10.0.2.2',
port: 3306,
user: 'root',
password:'',
db: 'master'
);
dynamic db = await MySqlConnection.connect(settings);
try{
print("Serach valuse is "+searchValue);
Results results = await (await db
.prepared('SELECT * from product WHERE productName LIKE "%?%"',[searchValue]))
.deStream();
await db.close();
print("AffectedRows"+results.affectedRows.toString());
print(results);
results.forEach((rw.Row rw) {print(rw[0]); });
return (results);
}catch(e){
print("Error01"+e.toString());
}
}}