lame php question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting lame php question
# 1  
Old 08-22-2006
lame php question

When do PHP variables/objects vanish?
Say, I have a database structure in index.php, I called connect(). Then I sent the user another page, say index2.php. Should I create a fresh database structure and call connect() again, or is there a way around this?
# 2  
Old 08-22-2006
Quote:
Originally Posted by rayne
When do PHP variables/objects vanish?
They won't. Really. Unless you purposely unset() them.

Quote:
Then I sent the user another page, say index2.php.
It really depends on how you "send". If you just require("index2.php") from within index.php, then variables in index.php will be available to index2.php. They won't vanish.

Quote:
Should I create a fresh database structure and call connect() again, or is there a way around this?
What do you mean by a "database structure"? Some table data fetched? or the database /statement handle itself?

If the "send" you meant is by means of an HTTP/meta redirect, you may always try to save some array or even objects into session. However, certain types such as database handles are not serializable and thus cannot be put in session. Therefore, you need to open a connection to the database for each HTTP request in this case.
# 3  
Old 08-23-2006
Quote:
Originally Posted by cbkihong
If the "send" you meant is by means of an HTTP/meta redirect, you may always try to save some array or even objects into session. However, certain types such as database handles are not serializable and thus cannot be put in session. Therefore, you need to open a connection to the database for each HTTP request in this case.
Try pconnect() (which means persistent connect). This function tries to pool connections and if there are some avail open connections it does not make new one each time but selects from the pool.
# 4  
Old 08-23-2006
I always avoid pconnect() because for mysql it is known to multiplex multiple connections to the same host for two databases. In the past I found this a harsh way. Wanting to open two connections to copy rows from one database to the next, and at the end everything was messed up badly.

Although the database connection is persistent, but on every page you still need to call connect to get the database handle, isn't it?
# 5  
Old 08-23-2006
Quote:
Originally Posted by cbkihong
I always avoid pconnect() because for mysql it is known to multiplex multiple connections to the same host for two databases. In the past I found this a harsh way. Wanting to open two connections to copy rows from one database to the next, and at the end everything was messed up badly.
You are totally right

Quote:
Originally Posted by cbkihong
Although the database connection is persistent, but on every page you still need to call connect to get the database handle, isn't it?
Yes, but the connectin is not dropped/created each time
# 6  
Old 08-23-2006
Quote:
Originally Posted by cbkihong
They won't. Really. Unless you purposely unset() them.

It really depends on how you "send". If you just require("index2.php") from within index.php, then variables in index.php will be available to index2.php. They won't vanish.
No, I mean this: I have index.php, some variables in it, and a URL to another page, say index2.php. When user clicks index2.php, previous variables no longer exists, right?

Quote:
Originally Posted by cbkihong
What do you mean by a "database structure"? Some table data fetched? or the database /statement handle itself?
I mean a PHP class that handles all SQL stuff. Has functions such as connect(), close(), fetchrow(), etc.

Quote:
Originally Posted by cbkihong
If the "send" you meant is by means of an HTTP/meta redirect, you may always try to save some array or even objects into session. However, certain types such as database handles are not serializable and thus cannot be put in session. Therefore, you need to open a connection to the database for each HTTP request in this case. Therefore, you need to open a connection to the database for each HTTP request in this case.
So, that can't be helped...
OK, thanks for the help!
# 7  
Old 08-23-2006
Quote:
Originally Posted by rayne
No, I mean this: I have index.php, some variables in it, and a URL to another page, say index2.php. When user clicks index2.php, previous variables no longer exists, right?
Right

Quote:
Originally Posted by rayne
I mean a PHP class that handles all SQL stuff. Has functions such as connect(), close(), fetchrow(), etc.
Check out http://www.kitebird.com/articles/peardb.html, this may help you
Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. What is on Your Mind?

Protocol Jokes (Lame)

I have a UDP joke but i don't know if you will get it: Also, I have a TCP joke and i know you will get it. :) (2 Replies)
Discussion started by: TUX servers
2 Replies

2. Shell Programming and Scripting

Help with 'batch conversion using lame' shell script

Hi. I am trying to write an sh script that will: 1. take each wav file in ~/Documents 2. convert each into mp3 format using "lame" encoder 3. save the new mp3 in ~/Documents/newmp3s. It has to follow the 3 steps in this order for each wav file before taking the next file. I tried a... (8 Replies)
Discussion started by: Kingzy
8 Replies

3. Shell Programming and Scripting

Delete original wav file if lame was successful encoding.

In a bash script: src=”cooltrack.wav” dst=”cooltrack.mp3” lame $src $dst I would like to add some line that would delete the source wav file like: rm $src but I would like this only if the encoding was successful. What should I include before deleting the original to check that the... (2 Replies)
Discussion started by: Aia
2 Replies

4. UNIX for Dummies Questions & Answers

Another lame 'vi' question......

This is a long shot, but there are many bright folks on here ;) My next vi drama involves a using a prototype file for a makefile. I have an old prototype file but its not in correct format. It's formated as: /the/old/path/file1 <garbage> <garbage> /the/old/path/file2 ... (3 Replies)
Discussion started by: Yinzer955i
3 Replies

5. Solaris

lame question

i have one stupid question... so please don't laught at me :-) actually i have linux on my pc, but i want to install a solaris... i heard that solaris is not free, but my friend said that there is a free solaris dostridution in gnu licence... is it real? if yes where can i get it? if no -... (4 Replies)
Discussion started by: pgas
4 Replies
Login or Register to Ask a Question