i see this, but also again not can do and bind param in select (mysql) On Sunday, March 5, 2017 at 2:09:04 PM UTC+3:30, Pierre Curto wrote: > > Have a look at https://golang.org/pkg/database/sql/#DB.Prepare. > > Le dimanche 5 mars 2017 11:07:28 UTC+1, erfang...@gmail.com a écrit : >> >> Hello, >> i want execute example `select * from <table> where id=?` with bind >> param(s) and get `all rows`. >> https://github.com/go-sql-driver/mysql/wiki/Examples >> >> ``` >> db, err := sql.Open("mysql", "user:password@/dbname") >> if err != nil { >> panic(err.Error()) // Just for example purpose. You should use >> proper error handling instead of panic >> } >> defer db.Close() >> // Execute the query >> rows, err := db.Query("SELECT * FROM table") >> if err != nil { >> panic(err.Error()) // proper error handling instead of panic in >> your app >> } >> // Get column names >> columns, err := rows.Columns() >> if err != nil { >> panic(err.Error()) // proper error handling instead of panic in >> your app >> } >> // Make a slice for the values >> values := make([]sql.RawBytes, len(columns)) >> // rows.Scan wants '[]interface{}' as an argument, so we must copy the >> // references into such a slice >> // See http://code.google.com/p/go-wiki/wiki/InterfaceSlice for >> details >> scanArgs := make([]interface{}, len(values)) >> for i := range values { >> scanArgs[i] = &values[i] >> } >> // Fetch rows >> for rows.Next() { >> // get RawBytes from data >> err = rows.Scan(scanArgs...) >> if err != nil { >> panic(err.Error()) // proper error handling instead of panic >> in your app >> } >> // Now do something with the data. >> // Here we just print each column as a string. >> var value string >> for i, col := range values { >> // Here we can check if the value is nil (NULL value) >> if col == nil { >> value = "NULL" >> } else { >> value = string(col) >> } >> fmt.Println(columns[i], ": ", value) >> } >> fmt.Println("-----------------------------------") >> } >> if err = rows.Err(); err != nil { >> panic(err.Error()) // proper error handling instead of panic in >> your app >> } >> ``` >> i want add bind param of `?` to this source. >> may help me? >> >> >> https://github.com/go-sql-driver/mysql/issues/548 >> >
-- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.