LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-18-2005, 02:43 PM   #1
ldp
Member
 
Registered: Apr 2004
Location: Belgium Antwerpen
Distribution: slackware - knoppix
Posts: 141

Rep: Reputation: 18
PHP & MYSQL => session object using db link resource


Hi,

I have a small web application that allows a user to login.
The user is a class object and has some methods like ->login($dblnk), -> ....
For these methods, it uses a resource variable that is the link to the database so it can perform some queries on it.
I want to store the instance of the user class in a $_SESSION['user'] variable but since session variables are not allowed to hold resources, it doesn't work and I get an error that indicates the resource is an invalid mysql resource.

I tried to work around this by not holding the resource variable in the class anymore and by passing it each time to the methods respectivly. But alas, I always get this same error.

Is there some way around this or is it just completely impossible to have methods that want to perform queries? I know that it works if I don't hold the class instance in a $_SESSION variable but then I have to recreate the instance every time.

Maybe I can write some function external to the class (so it's no longer in the $_session) that handles all queries and is called from the user class but that means quit a lot of work.

So any advice or suggestions are welcome.

regards,
Lieven
 
Old 03-18-2005, 03:07 PM   #2
TheLinuxDuck
Member
 
Registered: Sep 2002
Location: Tulsa, OK
Distribution: Slack, baby!
Posts: 349

Rep: Reputation: 33
AFAIK (and someone please correct me if I'm wrong), there is not a way to share a resource between separate calls to the web server, simple due to the stateless nature of web page serving. Although DB connections are somewhat expensive (time/processing, etc) to initiate, I believe that per-script initiation is your only course of action.

As long as the script initiates the connection only once at the start of the script and uses this open connection for the duration of the script execution, you should be fine.
 
Old 03-19-2005, 02:38 AM   #3
ldp
Member
 
Registered: Apr 2004
Location: Belgium Antwerpen
Distribution: slackware - knoppix
Posts: 141

Original Poster
Rep: Reputation: 18
Thanks, I know there is something like a persistant db connection but I prefer not to use it.

So I create another class that handles all database manipulations with methods to connect and issue queries. It will then return the retrieved rows (if any) in an array format. Or it returns true or false like the result of the query.
This class will not have to be stored in a $_SESSION variable so it should be no problem.

thanks,
Lieven
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Slackware guide for AMP Apache MySQL & PHP xushi Slackware 35 05-11-2006 11:18 AM
PHP - MySQL link StarLion Fedora 4 09-10-2005 11:05 AM
Updating MySQL DB when a link is clicked with PHP Erik Thorsson Programming 2 12-03-2004 07:35 AM
From RedHat9 to FreeBSD (Apache 2 & Mysql & PHP 4) guardian653 *BSD 5 12-11-2003 05:31 PM
php:passing a var by a link by using session norbs Programming 5 08-02-2002 03:50 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:30 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration