Sorry, I may be too late to help you, but the last few days have been pretty hectic around here and I'm just getting to checking a few mailing lists.... Anyway, I'm not sure you're connecting to the database properly. You could probably put your connection in a constructor function (in PHP 5 it's preferred to name your constructor __construct() although classname() is also valid) and then I think you also need to put $this-> in front of your $host, $user, and $pass vars. Additionally, you take $q as input on query() yet you try to refer to it in your method as $query.....
--- In [email protected], "at_da_sa" <[EMAIL PROTECTED]> wrote: > > Hi All, > I have a file with a class that it contains some functions for : > 1- connect to DB (main function) > 2- Query > 3- fetch_row > > and I have another file that it uses functions of above class. but > "query" and "fetch_row" classes doesn't work. > > If I write "query" and "fetch_row" in class2 instead of call class1 it > works. > > what can I do? > --------------------------------- > here is file 1: > --------------------------------- > <?php > class DbConnect > { > var $link; > > function DbConnect() > { > $host = ''; > $db = ''; > $user =''; > $pass = ''; > > $this->link = mysql_connect($host, $user, $pass) or die > ('could not connect to mysql : ' .mysql_error()); > mysql_select_db($db,$this->link) or die ('could not select db > : ' .mysql_error()); > register_shutdown_function(array(&$this, 'close')); > } > > function query($q) > { > return mysql_query($query, $this->link) or die ('could not > query table : ' .mysql_error()); > } > > > function fetchrow($result) > { > return mysql_fetch_row($result) or die ('could not fetch row : > ' .mysql_error()); > } > > function close() > { > mysql_close($this->link); > } > } > ?> > > --------------------------------- > And here is file 2: > --------------------------------- > <?php > require_once('DbConnector.php'); > $connector = new DbConnect(); > $result = $connector->query('SELECT * FROM articles'); > $row = $connector->fetchrow($result); > echo $row['ID']; > ?> >
