Re: Class's and Variables
| From: | daniel at electroteque dot org | Date: | Tue, 13 May 2003 23:36:30 +0000 |
| Subject: | Re: Class's and Variables | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-147509@lists.php.net to get a copy of this message | ||
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