我使用以下代码连接到 postgresql 数据库。它运作良好。但现在我想在启用 sslmode 的情况下连接它。任何人都可以帮助我实现这一目标。
NSString* portS = [NSNumber numberWithInteger:port].stringValue;
headerPG = PQsetdbLogin(serverName.UTF8String,portS.UTF8String,NULL,NULL,databaseName.UTF8String,
userName.UTF8String, password.UTF8String);
BOOL result = [self connected];
NSString *resultString;
if(!result){
//Error connection
[self errorPG];
resultString = @"Connection Failed";
}
else{
resultString = @"Connected Successfully";
}
return resultString;
我不知道如何使用以下功能。
PGconn *PQconnectdbParams(const char **keywords, const char **values, int expand_dbname);
如何在关键字、值等中提供数据。
提前致谢。
最佳答案
我自己得到了答案。
const char *const keywords[] = {[@"sslmode" UTF8String], [@"hostaddr" UTF8String], [@"port" UTF8String], [@"user" UTF8String], [@"password" UTF8String], [@"dbname" UTF8String]};
const char *const values[] = {[@"allow" UTF8String], [serverName UTF8String], [portS UTF8String],[userName UTF8String],[password UTF8String],[databaseName UTF8String]};
headerPG = PQconnectdbParams(keywords, values, 1);
keyword
数组包含 postgresql 的关键字,value
数组包含关键字数组中特定键的值。
关于objective-c - 如何在 Objective-C 的 postgresql 中将 sslmode 设置为允许,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31512397/