Re: Class's and Variables

From: Date: Wed, 14 May 2003 00:02:20 +0000
Subject: Re: Class's and Variables
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-147514@lists.php.net to get a copy of this message
Daniel, Thanks, So for the case of the $sql variable it's OK to just create it in the CopyFile() method ? I guess this means the $sql variable will never be a $this->sql variable. I know this will all work fine either way I'm just wanting to play by the convention. Thanks Rudi. daniel@electroteque.org wrote:
prob not conventional but i usually set the connection outside my classes then i import the connection id inside the constuctor so my connection object pointer from my db class is $db then inside the constructor it would look like $this->db = $GLOBALS['db']; so copy file would look like function CopyFile() { $sql = "INSERT INTO images ( i_base64 ) VALUES 'myImage');"; $this->db->query($query); $this->db->close(); }
Hi, I've got a PHP class off the web and there's a change or two I'd like to make to one of the functions. So I have a question on adding private variables. Let's say I want to connect to my database, Postgresql, is it OK to just add the required variable's to the method itself or should the variable's be set at the start of the class. I hope my code example below helps explain my question: class UploadImage { var $image; function UploadImage($image) { $this->image=stripslashes($image); } function CopyFile() { $conn = pg_connect("dbname=oasis_net"); $sql = "INSERT INTO images ( i_base64 ) VALUES 'myImage');"; $res = pg_exec($conn,$sql); $conn = pg_close($conn); } } Is it OK to set the $res variable in CopyFile() like above or should it be set where the $image variable is set. Thanks heaps. Regards Rudi. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.general (#147514) next »