User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 426,254 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,102 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting

OOPing with PHP4 simple DB connect class?

Join Date: Nov 2007
Posts: 86
Reputation: sagedavis is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 6
sagedavis sagedavis is offline Offline
Junior Poster in Training

OOPing with PHP4 simple DB connect class?

  #1  
Mar 27th, 2008
I am banging my head against the wall here.
I've tried everything that I can think of to get this to work.

class myData {
function myStuff($sql){
	$result = @mysql_query($sql,$connection) or die(mysql_error());
		while ($row = mysql_fetch_array($result)) {
		$adId = $row['adId'];
		$adName = $row['adName'];
		$adData .= "my adId is $adId and guess what? my adName is $adName <br/><br/>";
		
		}	
	}
}

Note, I am also using a "require_once" of a file which holds variables for
$connection = mysql_connect("localhost","maDB","maPassword") or die(mysql_error());
$db_name = "myDB";
$db = @mysql_select_db($db_name,$connection) or die(mysql_error);

in my index page I have the following

sql = "select * from tablename";
$objAdvertisers = new myData;
$objAdvertisers->myStuff($sql);

Using this method keeps giving me an error of
unexpected T_CLASS...

I've tried several other things, but I was almost sure that this was the way that it was sposed to work?

All I am trying to do is create a generic connect to database and pass $sql as an argument, then store some information based on that as an array for each record that matches my request.

I am using a PHP4 server.

Any help?
Thanks
Sage
AddThis Social Bookmark Button
Reply With Quote  
All times are GMT -4. The time now is 8:59 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC