导入第三方:libsqlite3.tbd
设置:-fno-objc-arc
设置路径:进入沙河
NSString *home=[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
//拼接路径
NSString *path=[home stringByAppendingPathComponent:@"student.db"];
pragma mark --fmdb打开操作
FMDatabase *fmdb=[[FMDatabase alloc]initWithPath:path];
if ([_fmdb open]) {
NSLog(@"打开成功");
}else{
NSLog(@"打开失败”);
pragma mark -- fmdb 具体操作 增 删 改 建表
NSString *deleteSql2=@"delete from t_student where age = ?";
[_fmdb executeUpdate:deleteSql2,@43];
pragma mark --FMDB 查询
//相当于直接返回一个句柄
FMResultSet *resultSet=[_fmdb executeQuery:selectSql];
//句柄不够
while ([resultSet next]) {
int ID=[resultSet intForColumn:@"ID"];
NSString *name=[resultSet stringForColumn:@"name"];
int age=[resultSet intForColumn:@"age"];
NSLog(@"ID = %d ,name = %@, age = %d",ID,name,age);
}
//关闭句柄
[resultSet close];
}