Re: Help with making a class or connect function

From: Date: Wed, 04 Sep 2002 03:40:06 +0000
Subject: Re: Help with making a class or connect function
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-21551@lists.php.net to get a copy of this message
I got it to work My problem was I didn't put include in function. So the class file should be like this <? class Connect { var $link; function Connect() { include('config.php'); $this->link = mysql_pconnect($sqlhost,$sqluser,$sqlpasswd); if (!$this->link) { printf("Could not connect to sql server"); } mysql_select_db($sqldatabase); }//end of function connect }//end of class ?> than to call the link I just did. $class = new Connect; $class->link; So anybody want more info on how to use this class I made email me at umbrellanetworks@canada.com cheers :) "Frank Mancuso" <umbrellanetworks@canada.com> wrote in message news:20020903003701.34097.qmail@pb1.pair.com... > Hi I made this. > > <? > //config.php > $sqlhost = "localhost"; > $sqluser = "root"; > $sqlpasswd = "password"; > $sqldatabase = "project"; > ?> > > <? > //sqlclass.php > require('config.php'); > class Connect { > > var $link; > > > function Connect() { > > $this->link = mysql_connect($sqlhost,$sqluser,$sqlpasswd); > $select = mysql_select_db($sqldatabase,$this->link); > > } > > } > > ?> > > > <? > //index.php > require('config.php'); > require('sql.php'); > > > $class = new Connect; > > > $query = "SELECT * from houses WHERE city='toronto'"; > > $result = mysql_query($query,$class->link); > > $row = mysql_fetch_array($result); > > echo "$row[title]" > ."$row[firstname]"; > > ?> > > > > What I'm trying to do is make a function or class that I can call up when > ever I want to connect to mysql. > If anyone can explain if I've done something wrong or if I'm not calling the > function up. > > >

« previous php.db (#21551) next »