我尝试使用sqlite3_open命令连接我的服务器!
我的问题......这可能吗?我得到了以下代码......
// Get the path to the documents directory and append the databaseName
databaseName = @"AnimalDatabase.sql";
NSString *serverpath = @"http://localhost/app/";
databasePath = [serverpath stringByAppendingPathComponent:databaseName];
and then this here
-(void) readAnimalsFromDatabase {
// Setup the database object
sqlite3 *database;
// Init the animals Array
animals = [[NSMutableArray alloc] init];
// Open the database from the users filessytem
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
// Setup the SQL Statement and compile it for faster access
const char *sqlStatement = "select * from animals";
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
// Loop through the results and add them to the feeds array
while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
// Read the data from the result row
NSString *aName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];
NSString *aDescription = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];
NSString *aImageUrl = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 3)];
// Create a new animal object with the data from the database
Animal *animal = [[Animal alloc] initWithName:aName description:aDescription url:aImageUrl];
// Add the animal object to the animals Array
[animals addObject:animal];
[animal release];
}
}
// Release the compiled statement from memory
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);
}
任何建议??
答案 0 :(得分:0)
在哪里可以看到SQLite可以从URL打开数据库? 它只能打开文件(或者在内存中创建临时数据库)。
答案 1 :(得分:0)
答案只是 NO ,无论如何你的代码中都有很多错误。例如:
databaseName = @"AnimalDatabase.sql";
你从哪里得到这个。 iPhone正在使用sqlite数据库,它与sql文件没有任何共同之处:)