It's a good idea to use a class say gateway where all
database access codes will be written.in this gateway class
you will implement db connection as follows -

first create another class -

Published in database