Using sql database driver
I referenced the post above. But worrying about executing an INSERT statement, where one of my fields is for datetime. I tried to do "NOW" (), but when I check mysql db, I see 0000-00-00 00:00:00. Does anyone know what I can use as a value to correctly insert a date-time?
In addition, I know that I can build a datetime using a run-time package, but I do not want to use the Go machine’s runtime label. I want the machine datetime to start mysql. Hency, why did I use "NOW ()".
stmt, err := db.Prepare("INSERT userinfo SET username=?,departname=?,created=?")
checkErr(err)
res, err := stmt.Exec("reckhou", "IT", "NOW()")
checkErr(err)
id, err := res.LastInsertId()
checkErr(err)
fmt.Println(id)
source
share