This is a creation in Article, where the information may have evolved or changed. Sqltest_go Note the point:
1. To introduce two packages
Import{_ "Github.com/go-sql-driver"; " Database/sql "}, where the first package is preceded by a" _ ", only the
The init function
2. When working with database data
Db,_: = sql. Open ("MySQL", addr)
Res: = db. Query ("SELECT * from user where username=?," Zs ") At this point res is a string of address characters
For Res. Next () {
var user user
Res. Scan (&user. Id,&user. Username,&user. Password)
} The number and type of functions in Scan () are the same as the number and type of database fields, otherwise the assignment fails
Sqltest_beego Note the point:
1.orm. RegisterDatabase ("Default", "MySQL", addr,30)//Open database driver, because Beego has been beego. Registerdriver () over MySQL
2.beego. The second parameter of router{} is prefixed with "{}"
3.this. Tplname values need to be placed in the Views folder, or the system will not find the file
4. HTTP cannot be used. Listenandserve (": 8080", nil) instead of httpport:8080 under conf/app.conf
5. var user user
O.raw (Sql,un). Queyrow (&user)//will put the retrieved first data in the user
var user []user
O.raw (Sql,un). Queryrow (&user)//will fail to assign value
var user []user
Res,_: = O.raw (Sql,un). QueryRows (&user)//only related to the name of the struct's field, type, and order, quantity Independent
6. Not clear Beego. What's the use of Registermodel (new User)?