亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

連接postgresql去

連接postgresql去

Go
白豬掌柜的 2022-10-24 10:00:05
package mainimport (    "database/sql"    "fmt"    "html/template"    "net/http"    "unicode"    _ "github.com/lib/pq"    "golang.org/x/crypto/bcrypt")/* const (    host = "localhost"    port = 5432    user = "postgres"    password = "*******"    dbname = "db") */var tpl *template.Templatevar db *sql.DBfunc main() {    tpl, _ = template.ParseGlob("templates/*.html")    var err error    db, err = sql.Open("postgresql", "root:password@tcp(localhost:localhost/db")    if err != nil {        panic(err.Error())    }    defer db.Close()    http.HandleFunc("/register", registerHandler)    http.HandleFunc("/registerauth", registerAuthHandler)    fmt.Println("Listening")    http.ListenAndServe("localhost:8080", nil)}當我運行它時,我得到一個錯誤:恐慌:sql:未知驅動程序“postgresql”(忘記導入?)順便說一句,我只是在網上上課,但他們使用的是 MySQL,而我使用的是 Postgres,我正在為我的論文做這個
查看完整描述

1 回答

?
qq_遁去的一_1

TA貢獻1725條經驗 獲得超8個贊

您應該使用“postgres”數據庫驅動程序字符串,而不是“postgresql”。



查看完整回答
反對 回復 2022-10-24
  • 1 回答
  • 0 關注
  • 85 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號