views:

2358

answers:

2

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]);

Use this code for connecting & receive information from remotedatabase. And also use some framework. AppKit.framework, Cocoa.framework, Carbon.framework, MCPKit_bundled.framework. But stile i didn't connect my application with remort database.

A: 

A little more info is needed, specifically, what is the IP of your iPhone? The reason I ask is because unless it's IP address is in a private C network (192.168.x.x) it's not going to be able to find the DB.

I would recommend setting the dbUrl to a publicly accessible IP address. This may take a little work (firewall, learning what your IP address is, etc.) but it should work then.

Also, printing the results of the failed connection would be useful (I assume that MCPConnection has this capability, beyond just success/failure)

KevinDTimm
A: 

hi i m getting error that "MCPConnection" is undeclear........ anybody know whats the reason plz help me ..i will be thank ful

Salman