I am trying to get a users ID from a database within a class, but I have very little to no experience with classes, how could I go about getting the uid from the DB and then return the uid?
so basically something like this,
class hello {
public function getUid(){
//connect to the db
//get all of the users info
$array = mysql_fetch_array($result);
$uid = $array['uid'];
return $uid;
}
}
Like I said, I am still new to classes, so any advice or help would be greatly appreciated!
Thanx in advance!
First build a MySQL class library... suiting the requirements like in this sample piece:
and the configuration file...
There is a problem with the way your code is written, not with the class. Take a closer look at this line:
This is the first time variable
$result
appears on the function. Therefore, it is not possible to communicate with the database.A possible pseudo-code would be:
uid
field.Have a look at the relevant documentation first:
You can use custom database class.
Code :
Try following:
Alright, one piece of advice:
Do everything for a reason. Don't use things you don't know. Go and learn them instead.
One may give you an answer for this specific question, but until you don't know what Object Oriented means and why there are classes at all, you shouldn't use them.