简体   繁体   中英

getting mysql Error 1064

I am build a basic application with golang, i am using github.com/go-sql-driver/mysql driver. I am connecting to clearDB mysql on heroku but every time i'm getting

Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc, price from product where id = ?' at line 1

I can't under stand why, this is the piece of code that i'm using for the query the product database.

   id := c.Param("id")
    row := db.QueryRow("select id, desc, price from product where id = ?;", id)
            err := row.Scan(&product.Id, &product.desc, &product.price)

desc is a keyword so you get in trouble when you also named a column desc .

With MySQL you need to quote the name with backticks, like so:

"select id, `desc`, price from product where id = ?"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM