0

I have long known that one could fetch results from a mysql table and print it as :

(MySQL C API)

MYSQL_RES *result = mysql_store_result(con);

if (result == NULL)    
{    
  finish_with_error(con);    
}

int num_fields = mysql_num_fields(result);        
MYSQL_ROW row;        
while ((row = mysql_fetch_row(result)))    
{     
   printf("%s ", row[i] ? row[i] : "NULL");    
}

Now suppose I have to copy a database into another, can I do the other way round i.e can I somehow use the row variable to insert into the new database.

If I could do this copying a database would be so easy.

By copying a database I mean I have to create a database that is exactly the same as the original one, with all its data and attributes being the same.

1 Answer 1

1

I think prepared statements/PDO should work for what you're looking for. Without knowing what your table schema looks like, it's a bit hard to tell you what the statement would look like, but here's some information for the C API.

http://dev.mysql.com/doc/refman/5.1/en/c-api-prepared-statements.html http://dev.mysql.com/doc/refman/5.0/en/c-api-prepared-statement-data-structures.html http://dev.mysql.com/doc/refman/5.1/en/sql-syntax-prepared-statements.html

Sign up to request clarification or add additional context in comments.

5 Comments

i intend to transfer mysql database from one client to another, through sockets and mysql c api.
please give a few more hints.
So you are looking for a function to copy the database, or you have the new database and you are looking to load the data into it?
i have a database on my client 1, i have to create a copy of that database on client 2 all connected through tcp sockets. i must do it through mysql c api.
Hmm.. If you have to copy the database as well as the data, then I don't think prepared statements are your best option actually. They're good for queries such as simple inserts, but for copying an entire database I think you'll want something heftier.

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.