1

I'm trying to figure out the correct way to pass database connection parameters to this libpq connection control function.

PQconnectdbParams

PGconn *PQconnectdbParams(const char * const *keywords,
    const char * const *values, int expand_dbname);  

1 Answer 1

2

From the documentation:

This function opens a new database connection using the parameters taken from two NULL-terminated arrays. The first, keywords, is defined as an array of strings, each one being a key word. The second, values, gives the value for each key word.

I have never used this function in practice (as PQconnectdb() seems simpler), but this example should work I think:

char *keywords[] = {"hostaddr", "port", "dbname", 0};
char *values[] = {"127.0.0.1", "5432", "testdb", 0};

conn = PQconnectdbParams((const char **)keywords, (const char **)values, 0);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.