0

I connect and transform some table data in db1. Further down I want to send that data to a table in a different database db2.

MYSQL* conn;
conn = mysql_init(0);
conn = mysql_real_connect(conn, "localhost", "root", "password", "db1", 3306, NULL, 0);

if (conn) {
        ...
        // transform data

        // Connect to "db2" and insert data into table

Do I need to use CLIENT_MULTI_RESULTS when establishing a connection? Or create a new conn?

1
  • Is db2 in the same mysql instance as db1? Commented Mar 24, 2020 at 9:58

1 Answer 1

-1

I figured it out. Just creating another variable and calling it later worked.

MYSQL* conn;
MYSQL* conn2;
conn = mysql_init(0);
conn2 = mysql_init(0);
conn = mysql_real_connect(conn, "localhost", "root", "password", "db1", 3306, NULL, 0);
conn2 = mysql_real_connect(conn2, "localhost", "root", "password", "db2", 3306, NULL, 0);

...

if(conn)
{ 
    puts("CONN CONNECTION SUCCESSFUL")
    ...        
    if(conn2)
    {
        puts("CONN2 CONNECTION SUCCESSFUL")
        ...
Sign up to request clarification or add additional context in comments.

3 Comments

If the two databases are in single mysql instance, then you only need 1 connection. Use dbnane.tablename method to access a table in the other database.
Could you provide an example please?

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.