1 回答
TA贡献1828条经验 获得超3个赞
import (
"database/sql"
"net/http"
)
func VerifyUser(user User) (*User, string, error) {
db, ctx := db.GetDB()
query := "CALL usp_GetUserByUsername(?)"
stmt, err := db.Prepare(query)
if err != nil {
log.Errorln("Error in preparing statement. " + err.Error())
return nil, "Error in preparing statement.", err
}
defer stmt.Close()
row := stmt.QueryRowContext(ctx, user.Email)
var retUser User
err = row.Scan(&retUser.ID, &retUser.Email, &retUser.Password, &retUser.Status)
if err != nil {
log.Warningln("Unknown Email: " + user.Email + ". " + err.Error())
return nil, "Invalid user.", err
}
将查询中的@Email 替换为 ? 并将电子邮件传递到 QueryRowContext not named statement
- 1 回答
- 0 关注
- 143 浏览
添加回答
举报