MCPResult * theResult; MCPConnection * mySQLConnection;
//initialize connection string vars
NSString *dbURL = @"192.168.0.16";
NSString *userName = @"";
NSString *pass = @"";
int port = 3306;
//open connection to database
mySQLConnection = [[MCPConnection alloc] initToHost: dbURL
withLogin:userName
password:pass
usingPort:port];
if ([mySQLConnection isConnected])
{
NSLog(@"The connection to database was successfull");
}
else
{
NSLog(@"The connection to database was failed");
}
//selection to database
if([mySQLConnection selectDB:@"blackjack_DB"])
{
NSLog(@"Database found");
}
else
{
NSLog(@"Database not found");
}
//selection to Table
theResult = [mySQLConnection queryString:@"select * from test"];
//theResult = [mySQLConnection queryString:@"select * from test where id='1'"];
//theResult = [mySQLConnection queryString:@"select id from test"];
//theResult = [mySQLConnection queryString:@"select name from test where pass='main_pass'"];
NSArray *m= [theResult fetchRowAsArray];
NSLog(@"%@", m);
NSLog(@"%@", [m objectAtIndex:2]);
使用此代码连接&从远程数据库接收信息。 并且还使用一些框架。 AppKit.framework,Cocoa.framework,Carbon.framework,MCPKit_bundled.framework。但是我没有将我的应用程序与remort数据库连接起来。
答案 0 :(得分:0)
需要更多信息,具体来说,iPhone的IP是多少?我问的原因是因为除非它的IP地址在私有C网络(192.168.x.x)中,否则它将无法找到数据库。
我建议将dbUrl设置为可公开访问的IP地址。这可能需要一些工作(防火墙,了解你的IP地址等等),但它应该工作。
此外,打印失败连接的结果将非常有用(我假设MCPConnection具有此功能,而不仅仅是成功/失败)