[Tutor] Exceptions while dealing with MySQL

Alan Gauld alan.gauld at btinternet.com
Tue Apr 24 19:49:03 CEST 2007


"Thanos Panousis" <pthanos at gmail.com> wrote

> data. Say for each person object, I need an object variable called
> "hairColor". This haircolor variable has to be filled through an SQL
> query, so the object must have some way to access a database cursor.
> The cool thing would be that all person objects use the same
> connection/cursor to get their haircolors filled in, so there would 
> be
> only one connection to the SQL server.
>
> Could this  done with a class variable? From what I understand, it
> fits nice because its available to all objects of the class,

Absolutely and that would be a good choice provided you don't
need connections/cursors from each class to the same database.
If that's the case you may prefer to create the connection globally
and pass a reference into your classes via init.

Alan G. 




More information about the Tutor mailing list