0

After my connection to database, I surely insert elements to my table one by one, but I do not have any idea about inserting elements from an array, vector..etc to tables. Following query is that I tried, but no effects on table.

mysql_query(connection,"insert into mytable (id) values(arr[0])");  
1
  • 1
    "insert into mytable (id) values(arr[0])" -> This is a constant string, nothing will be replace for arr[0] from your array/vector Commented Jan 17, 2012 at 16:34

1 Answer 1

1

C/C++ don't interpolate values into a string as most scripting languages do. You'll have to use string operations to build the query string, e.g. (in pseudo-code):

str = "insert into mytable(id) values (" + arr[0] + ")";

instead. C has absolutely no way of knowing that arr[0] in that query string should be treated as an array reference, and not just plain text that happens to look like one. Hence having to build the string yourself.

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.