开发者

how do I insert a string datetime into mysql using c++

开发者 https://www.devze.com 2023-01-06 00:59 出处:网络
I have a datetime field in the following format: string date = \"J开发者_如何学Cun 23 19:47:15 +0000 2010\";

I have a datetime field in the following format:

string date = "J开发者_如何学Cun 23 19:47:15 +0000 2010";
how do I insert it ito datetime field in mysql table? I am assuming I have to convert the date into unix timestamp before I insert it into the table.


First, you've got an sql-injection attack waiting to happen. Had to be said.

Ok, that huge problem swept aside, you can either convert the date to a MySQL format (such as a UTC timestamp then converted again with FROM_UNIXTIME()), or tell MySQL how to convert it using STR_TO_DATE(). Both are documented in the MySQL manual, under the section "Date and Time Functions".


You create an SQL statement to do so and then call an SQL API to tell the SQL server to execute your statement.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号