Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 使用Cocos2d与我的iPhone应用程序建立远程数据库连接_Mysql_Iphone_Cocos2d Iphone - Fatal编程技术网

Mysql 使用Cocos2d与我的iPhone应用程序建立远程数据库连接

Mysql 使用Cocos2d与我的iPhone应用程序建立远程数据库连接,mysql,iphone,cocos2d-iphone,Mysql,Iphone,Cocos2d Iphone,结果*结果; 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]

结果*结果; 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]);
使用此代码连接并从remotedatabase接收信息。
并使用一些框架。AppKit.framework、Cocoa.framework、Carbon.framework、MCPKit_bundle.framework。但是我没有将我的应用程序与Remot数据库连接。

需要更多的信息,特别是,你的iPhone的IP是多少?我问这个问题的原因是,除非它的IP地址在专用C网络(192.168.x.x)中,否则它将无法找到数据库

我建议将dbUrl设置为可公开访问的IP地址。这可能需要一点工作(防火墙、了解您的IP地址等),但它应该可以工作

此外,打印失败连接的结果也很有用(我假设MCPConnection除了成功/失败之外还具有此功能)