Re: using require

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

 



Hello!

On Fri, 2005-10-14 at 11:33 -0700, Cima wrote:
> hi all,
> 
> 
> i have my web site working something like this: in every php script i have require(auth.php). this auth.php has my connection to my postgresql server and database along with some other stuff i need for the user to be authenticated to my web site. when i log on, this auth.php connects to the dbserver and checks if my username and password are stored and then i go to a home page. my connection is stored in $dbh. 
> what happens when i start moving through all these web pages (php scripts), each requires auth.php, with respect to the connection? is a new connection established for every web page i go into that uses my $dbh for querying purposes or is it the same connection i originally made when i first logged into the web site?
> 

According to the manual
(http://www.php.net/manual/en/function.pg-connect.php), you should be
using the same connection.

If I might make some recommendations: unless you're doing something
unique as part of the login process, it might be worthwhile looking at
the LiveAdmin authentication system.  It's available via pear.  It
allows you to set up authentication containers, which can be an XML file
holding your usernames/passwords, or a database like Postgres.  It also
has containers for permissions.  I've tested in a couple of simple apps
and it works fairly well.

If LiveAdmin doesn't fit your needs, then you might look at Propel
(http://propel.phpdb.org/trac/), it's an object persistence layer which
provides a couple of benefits: 1) it abstracts your database so you
don't have hand-coded SQL scattered throughout your PHP code and you
don't have to mess around with the details of connecting to the db; 2)
it provides a pretty sweet build tool that takes an SQL schema
definition (marked up in XML) for a database and generates not only your
SQL to create the tables but also your PHP classes.  Then in your
application you only need to be concerned with using the generated
classes.  

I realize this isn't what you asked about, but I've used Propel in a
couple of small web apps and I've been really happy with it.  It cut the
number of lines of code in my main application by almost half.
Moreover, it helped simplify making changes to the db: if I need to
change a field in a table, add/delete a field, or add a whole new table,
I simply make the change in my schema file, re-generate my PHP classes,
and then use the new classes in my app.  I don't have to search through
a bunch of code to find all the instances of a particular SQL statement.

HTH,
Tim

 

> 
> any info will be highly appreciated!!
> 
> 
> thanx.
-- 
Tim Boring
IT Manager
Automotive Distributors Warehouse
2981 Morse Road
Columbus, OH 43231
Toll Free: 800-421-5556, x3007
Direct: 614-532-4240
E-mail: tboring@xxxxxxxx

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux