How to insert array elements in sql connecting wit

2019-08-22 09:08发布

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条回答
We Are One
2楼-- · 2019-08-22 09:10

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.

查看更多
登录 后发表回答