I am trying to fetch multiple column in a mysql database using the go language. Currently I could modify this script and it would work perfectly well for just fetching one column and printing it using the http print function. However when it fetch two things the script nolongerworks. I don't have any idea what i need to do to fix it. I know that the sql is fine as i have tested that out in the mysql terminal and it has given me the expect result that I wanted. I
conn, err := sql.Open("mysql", "user:password@tcp(localhost:3306)/database")
statement, err := conn.Prepare("select first,second from table")
rows, err := statement.Query()
for rows.Next() {
var name string
rows.Scan(&first)
var url string
rows.Scan(&second)
fmt.Fprintf(w, "Title of first is :"+first+"The second is"+second)
}
conn.Close()
Please don't down vote.
Aucun commentaire:
Enregistrer un commentaire