close
import( "database/sql" _ "github.com/go-sql-driver/mysql" ) var connectionString = fmt.Sprintf( "%s:%s@tcp(%s:3306)/%s?allowNativePasswords=true", db_userName, db_password, db_host, db_name) func Test(name string, passwrd string, phone string) string { db, err := sql.Open("mysql", connectionString) if err != nil { return err.Error() } defer db.Close() cmd, err := db.Exec("INSERT INTO TableName(UserName, Password,PhoneNumb) VALUE(?,?,?)", name, passwrd, phone) if err != nil { return err.Error() } _, err = cmd.RowsAffected() if err != nil { return err.Error() } else { return "SUCCESS" } }
文章標籤
全站熱搜
留言列表