on 1/26/02 1:21 AM, jas at [EMAIL PROTECTED] appended the following bits
to my mbox:

> Ok, I am having a hard time coming up with a mysql connection class that
> simply allows me to setup a require(db_connection.inc) at the top of my php
> pages that allows a consistent connection to the mysql db and allows
> multiple queries thoughout the php page in question.  I have read a few
> tutorials on it and as of yet they all seem to go over my head.  If someone
> could give me some more insight into this area I would greatly appriciate
> it.

I don't think you really need a connection class, per se.  What you want to
do is write the connection code for the database once and then be able to
use it in all of your pages, correct.

How about this:

$dbh = mysql_connect('host','user','password');

Then in each file, at the top:
<?php require './db_connection.php'; ?>

And you would call your queries like this:

$query = 'SELECT au FROM pb WHERE alchemy!="junk_science"';
$res = mysql_query($query, $dbh);

>From there you need to use the fetch_row/array functions as described in the
PHP manual.

If not using MySQL, change the "connect" call to the appropriate function.

The above assumes that you are just talking to tables in one database.  If
using more databases, put the select_db call in the individual files.

Also, if your db_connection.php file isn't in the same directory as the
files requiring it, use an absolute location or put the file in your include



    while ($self != "asleep") {

PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to