Problem with using php classes
Posted: Sat Jul 08, 2006 11:39 pm
Hiya folks.
I'm currently building a personal site of my own, and i'm having a bit of a problem as far as getting information from the database using adodb. Its kinda hard for me to explain so I'll print out the code.
The above code works just fine. No problems at all, but I was trying to put the connection part into a class so that I wouldn't have to type in those lines all the time, all I would have to do is call to the class object and execute my query from there on.
This code doesn't work, I would like it to(thats the way I would like to call the class) but it keeps saying :
I'm currently building a personal site of my own, and i'm having a bit of a problem as far as getting information from the database using adodb. Its kinda hard for me to explain so I'll print out the code.
Code: Select all
require_once('/adodb/adob.inc.php');
$db = ADONewConnection('mysql');
$db->Connect("host","username","pass","database");
$sql = "SELECT * FROM updates";
$rs = $db->Execute($sql) or die("SQL Error : ".$db->ErrorMsg());
while(!$rs->EOF){
echo $rs->fields('title')."<br/>".$rs->fields('body')."<br><br>";
$rs->MoveNext();
}Code: Select all
class data {
function data(){
$db = ADONewConnection('mysql');
$db->Connect("host","username","pass","database");
}
}
$nd = new data;
$sql = "SELECT * FROM updates";
$rs = $nd->Execute($sql);
while(!$rs->EOF){
echo $rs->fields('title')."<br/>".$rs->fields('body')."<br><br>";
$rs->MoveNext();
}any suggestions? I'm on PHP4.4xx so the '__construct()' function is kinda useless to me at the moment.Fatal error: Call to undefined function: fields() in /home/www/host_name/classes/class.connect.php on line 28