You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
err = db.Ping() //"Ping" checks if a connection to a database is still live, and returns an error if it isnt (so if theres no error it means its connected).
if err != nil {
panic(err)
}
fmt.Println("You've connected to your database")
}
postgreSQL CODE:
postgres=# CREATE DATABASE bookstore;
CREATE DATABASE
postgres=# CREATE USER bond WITH PASSWORD 'password';
CREATE ROLE
postgres=# GRANT ALL PRIVILEGES ON DATABASE bookstore to bond;
GRANT
The text was updated successfully, but these errors were encountered:
I keep getting the following error: panic: pq: password authentication failed for user "bond"
I cannot find what's wrong with the code, as it's the one that was used in the course, and in the course it ran perfectly.
Can you find the problem?
GO CODE:
package main
import (
"database/sql"
"fmt"
)
func main() {
db, err := sql.Open("postgres", "postgres://bond:password@localhost/bookstore?sslmode=disable")
if err != nil {
panic(err)
}
defer db.Close()
}
postgreSQL CODE:
postgres=# CREATE DATABASE bookstore;
CREATE DATABASE
postgres=# CREATE USER bond WITH PASSWORD 'password';
CREATE ROLE
postgres=# GRANT ALL PRIVILEGES ON DATABASE bookstore to bond;
GRANT
The text was updated successfully, but these errors were encountered: