On Thu, Dec 12, 2013 at 5:10 PM, Ken GoNoob <
drke...@gmail.com> wrote:
> I'm trying to create a global "DB" type variable after opening with
> sql.Open(). Conceptually something like:
>
> var MyDB *DB // this fails - DB is not a recognized type
You probably mean *sql.DB, here.
>
> func init() {
> MyDB, err = sql.Open(DBparms....)
> }
>
> func accessDB()
> rows, err := MyDB.Query(query...) // use the db connection that was
> opened in init()
> }
>
> I've tried a variety of things to make a global "DB" or "*DB" variable, but
> I'm not getting how it's supposed to work. Does MyDB have to be passed as an
> argument to all of the functions requiring it?
> If so, how do you declare the functions since it doesn't recognize DB as a
> valid type?
> Ken
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to
golang-nuts...@googlegroups.com.
> For more options, visit
https://groups.google.com/groups/opt_out.