2012-01-11 39 views
-2

我有一個使用phpMyAdmin創建的數據庫。我需要將數據庫連接到我的iPhone應用程序以檢索某些數據,但我不知道應該使用哪種類型的Web服務以及我應該如何將它們連接在一起。將數據庫連接到iPhone應用程序

有誰知道如何將數據庫連接到iphone應用程序? 有沒有我可以關注的網站? 我將不勝感激您的幫助!

感謝

回答

2

你可以看看this

一旦你完成了你的API的編寫,你可以在iPhone上使用here的提示。

0

只需將數據庫文件拖放到項目導航器中的資源文件夾,即可將數據庫文件添加到項目中。確保在提示時將其添加到所需的目標。然後您可以使用SQLite庫來讀取/寫入數據庫。

0

只需將數據庫文件拖到項目導航器中的資源文件夾,即可將數據庫文件添加到項目中。確保在提示時將其添加到所需的目標。

使用此代碼加載你的sqlite的文件

-(void) getdatabasePath 
{ 

    NSString *databaseName = [NSString stringWithFormat:@"%@", @"Database.sqlite"]; 

//Get the path to the Document and append the databaseName 
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,  NSUserDomainMask, YES); 
NSString *documetsDir = [documentPaths objectAtIndex:0]; 
databasePath = [[documetsDir stringByAppendingPathComponent:databaseName] retain]; 

// Check if the SQL database has already been saved to the users phone, if not then copy it over 
BOOL success; 
NSFileManager *fileManager = [NSFileManager defaultManager]; 
success = [fileManager fileExistsAtPath:databasePath]; 
if(success) return; 

// If not then proceed to copy the database from the application to the users filesystem 
NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:databaseName]; 
[fileManager copyItemAtPath:databasePathFromApp toPath:databasePath error:nil]; 
    } 
相關問題