更改資料庫連接,testdb->care(HistoricalPage)

This commit is contained in:
kuei
2024-09-04 09:42:26 +08:00
parent 968ef745a2
commit 7fb6d59c1c
2 changed files with 21 additions and 23 deletions

View File

@@ -29,20 +29,20 @@ class _HistoricalRecordState extends State<HistoricalRecord> {
print('connect');
final conn = await MySQLConnection.createConnection(
//host: '203.64.84.154',
host: '10.0.2.2',
host: '203.64.84.154',
//host: '10.0.2.2',
//127.0.0.1 10.0.2.2
port: 3306,
port: 33061,
userName: 'root',
//password: 'Topic@2024',
password: '0000',
//databaseName: 'care', //testdb
databaseName: 'testdb',
password: 'Topic@2024',
//password: '0000',
databaseName: 'care', //testdb
//databaseName: 'testdb',
);
await conn.connect();
try {
var result = await conn.execute('SELECT * FROM users');
var result = await conn.execute('SELECT HomeElderFall.*, HomeElder.heName FROM HomeElderFall JOIN HomeElder ON HomeElderFall.heId = HomeElder.heId;');
print('Result: ${result.length} rows found.');
if (result.rows.isEmpty) {
@@ -51,13 +51,11 @@ class _HistoricalRecordState extends State<HistoricalRecord> {
setState(() {
_results = result.rows
.map((row) => {
'id': row.colAt(0),
'name': row.colAt(1),
'age': row.colAt(2),
'gender': row.colAt(3),
'phone': row.colAt(4),
'email': row.colAt(5),
'password': row.colAt(2)
'長者ID': row.colAt(0),//去裝資料庫的行數
'姓名': row.colAt(8),
'跌倒時間': row.colAt(1),
'跌倒原因': row.colAt(2),
'跌倒地點': row.colAt(7),
})
.toList();
});
@@ -93,12 +91,12 @@ class _HistoricalRecordState extends State<HistoricalRecord> {
itemCount: _results.length,
itemBuilder: (context, index) {
return ListTile(
title: Text(_results[index]['name']),
title: Text(_results[index]['姓名']),
subtitle: Text(
'age: ${_results[index]['age']}, '
'gender: ${_results[index]['gender']}, '
'phone: ${_results[index]['phone']}, '
'email: ${_results[index]['email']}',
'長者ID: ${_results[index]['長者ID']}\n, '
'跌倒時間: ${_results[index]['跌倒時間']}\n, '
'跌倒原因: ${_results[index]['跌倒原因']}\n, '
'跌倒地點: ${_results[index]['跌倒地點']}\n',
),
);
},

View File

@@ -80,7 +80,7 @@ class _PersonalInfoState extends State<PersonalInfo> {
}
void _saveChanges() async {
/*final conn = await MySQLConnection.createConnection(
final conn = await MySQLConnection.createConnection(
host: '203.64.84.154',
port: 33061,
userName: 'root',
@@ -88,7 +88,7 @@ class _PersonalInfoState extends State<PersonalInfo> {
databaseName: 'care',
);
await conn.connect();*/
await conn.connect();
try {
await conn.execute(