[PHP] What is the proper way to use mysql db on a multipage site?

2003-09-26 Thread Daevid Vincent
I sent this to php-db with no reply, so I'll try it here then...
 

-Original Message-
From: Daevid Vincent [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, September 24, 2003 4:21 PM
To: [EMAIL PROTECTED]
Subject: [PHP-DB] What is the proper way to use mysql db on a multipage
site?


I've been coding with PHP and mySQL for years. And this part has never sat
right with me and finally I'm getting the nerve to ask how the pros out
there do this...

What I do is have a db.php file that contains:

$db = mysql_connect (localhost,username,password) 
or die (Could not connect to SQL server.);
mysql_select_db (mydb,$db) 
or die (Could not select Database);


Then at the top of every page, I require_once(db.php);

But it just seems so wasteful to keep making that mysql_connect().

Isn't there a way to store the $db result so I don't have to keep
connecting.
And how about the mysql_select_db() part too? Since I'm going to stay in the
same db most of the time.

I thought I read that I can't use a $_SESSION for it, and that's the only
way I know of to have it be available on each page?


Daevid Vincent
http://daevid.com
 

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

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



Re: [PHP] What is the proper way to use mysql db on a multipage site?

2003-09-26 Thread Robert Cummings
Mostly a matter of preference I would say.

Cheers,
Rob.

On Fri, 2003-09-26 at 16:10, Daevid Vincent wrote:
 I sent this to php-db with no reply, so I'll try it here then...
  
 
 -Original Message-
 From: Daevid Vincent [mailto:[EMAIL PROTECTED] 
 Sent: Wednesday, September 24, 2003 4:21 PM
 To: [EMAIL PROTECTED]
 Subject: [PHP-DB] What is the proper way to use mysql db on a multipage
 site?
 
 
 I've been coding with PHP and mySQL for years. And this part has never sat
 right with me and finally I'm getting the nerve to ask how the pros out
 there do this...
 
 What I do is have a db.php file that contains:
 
 $db = mysql_connect (localhost,username,password) 
   or die (Could not connect to SQL server.);
 mysql_select_db (mydb,$db) 
   or die (Could not select Database);
 
 
 Then at the top of every page, I require_once(db.php);
 
 But it just seems so wasteful to keep making that mysql_connect().
 
 Isn't there a way to store the $db result so I don't have to keep
 connecting.
 And how about the mysql_select_db() part too? Since I'm going to stay in the
 same db most of the time.
 
 I thought I read that I can't use a $_SESSION for it, and that's the only
 way I know of to have it be available on each page?
 
 
 Daevid Vincent
 http://daevid.com
  
 
 -- 
 PHP Database Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

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



Re: [PHP] What is the proper way to use mysql db on a multipage site?

2003-09-26 Thread Brent Baisley
It does seem wasteful, but you have to make sure there is a connection 
before you query a database. What if the user goes out to lunch? Should 
you maintain an open database connection for an hour? No, that's a lot 
of overhead.
What you can do is change it from mysql_connect to mysql_pconnect. That 
will make it a persistent connection, which may be what you are looking 
for. It actually leaves the connection open after it's done using, 
which is just what I said you don't want to do. But what PHP does is 
reuse open connections to the database. You could have 30 users 
visiting your site, but only 5 active at any one time. PHP will then 
use only 5 database connections.
You are still making the connection call, but PHP will just say OK, I 
already have one I can use and here is it's id.

On Friday, September 26, 2003, at 04:10 PM, Daevid Vincent wrote:

I've been coding with PHP and mySQL for years. And this part has never 
sat
right with me and finally I'm getting the nerve to ask how the pros out
there do this...

What I do is have a db.php file that contains:

$db = mysql_connect (localhost,username,password)
or die (Could not connect to SQL server.);
mysql_select_db (mydb,$db)
or die (Could not select Database);
Then at the top of every page, I require_once(db.php);

But it just seems so wasteful to keep making that mysql_connect().

Isn't there a way to store the $db result so I don't have to keep
connecting.
And how about the mysql_select_db() part too? Since I'm going to stay 
in the
same db most of the time.

I thought I read that I can't use a $_SESSION for it, and that's the 
only
way I know of to have it be available on each page?

--
Brent Baisley
Systems Architect
Landover Associates, Inc.
Search  Advisory Services for Advanced Technology Environments
p: 212.759.6400/800.759.0577
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] What is the proper way to use mysql db on a multipage site?

2003-09-26 Thread Chris Shiflett
--- Daevid Vincent [EMAIL PROTECTED] wrote:
 But it just seems so wasteful to keep making that mysql_connect().
 
 Isn't there a way to store the $db result so I don't have to keep
 connecting.

http://www.php.net/mysql_pconnect

Hope that helps.

Chris

=
Become a better Web developer with the HTTP Developer's Handbook
http://httphandbook.org/

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



Re: [PHP] What is the proper way to use mysql db on a multipage site?

2003-09-26 Thread Jackson Miller
On Friday 26 September 2003 3:54, Chris Shiflett wrote:
 http://www.php.net/mysql_pconnect

If you have even moderate load on your server mysql_pconnect is going to 
really hurt performance.

The best method I have found is to just make sure the connection code is only 
in one file and then included into each of your scripts.

No matter what, every page load from the webserver that needs database 
connectivity is going to have to connect to the database.

-Jackson



 Hope that helps.

 Chris

 =
 Become a better Web developer with the HTTP Developer's Handbook
 http://httphandbook.org/

-- 
jackson miller
 
cold feet creative
615.321.3300 / 800.595.4401
[EMAIL PROTECTED]
 
 
cold feet presents Emma
the world's easiest email marketing
Learn more @  http://www.myemma.com

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