RE: Using Objects with Databases

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I store all my sql queries in an include file.
These queries could store the actions you want to perform for each user..

I then use scripts to execute queries (with an alias name for each) based on
decisions (such as whether certain $_POST variables are present etc..)

If I were building a 'user' class -> I would store the actions that would
'call' the appropriate query by it's alias. This allows other objects to
perform the same queries without re-writing them inside a different class.

Also - I'm using a database abstraction layer so I don't have database
specific calls inside my classes. This helps maintain portability of my
applications.

Hope that helps.

LW






-----Original Message-----
From: Philip Zee [mailto:pzee@creativecgi.com]
Sent: Wednesday, 22 January 2003 5:16 PM
To: Luke Woollard; PHP-db
Subject: RE:  Using Objects with Databases


Luke,

Thanks for the help.  This only answers half of my question.  I understand
that
you need to build a class to handle your database needs.  However, once the
database returns a row in the table "user", there will be functions
performed
for that user.  I was thinking about creating a class "User" to handle the
initialization and other functions for the user.  What's the best way of
doing
that?

Thanks,

Philip

-----Original Message-----
From: Luke Woollard [mailto:luke@taborvision.com]
Sent: Tuesday, January 21, 2003 9:38 PM
To: PHP-db
Subject: RE:  Using Objects with Databases


Initialise the database connection and perform actions on the database using
a seperate class.
You can pass your functions (methods) values returned from your database
calls to manipulate.

This is commonly called a 'database abstaction layer'

Theres a good database abstraction class in this magazine by a guy called
marco talbini http://www.phparch.com/

Else lookup PEAR:MB or adodb library on teoma.com or similar.





-----Original Message-----
From: Philip Zee [mailto:pzee@creativecgi.com]
Sent: Wednesday, 22 January 2003 4:27 PM
To:
Subject:  Using Objects with Databases


Hello all,

I am trying to create a class, say User.  Each user has an entry in the
database
table called user.  Each function, including the constructor, will be
calling
the database to do something.  Is it better to initialize the database
connection inside each function or is it better to initialize the connection
at
the beginning of the class?  What's the best practice on this?

Any help or example is appreciated.

Thanks,

Philip


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux