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
Try following:
ini_set("display_errors", 'off');
ini_set("error_reporting",E_ALL);
class myclass {
function myclass() {
$user = "root";
$pass = "";
$server = "localhost";
$dbase = "";
$conn = mysql_connect($server,$user,$pass);
if(!$conn)
{
$this->error("Connection attempt failed");
}
if(!mysql_select_db($dbase,$conn))
{
$this->error("Dbase Select failed");
}
$this->CONN = $conn;
return true;
}
function close() {
$conn = $this->CONN ;
$close = mysql_close($conn);
if(!$close)
{
$this->error("Connection close failed");
}
return true;
} function sql_query($sql="") {
if(empty($sql))
{
return false;
}
if(empty($this->CONN))
{
return false;
}
$conn = $this->CONN;
$results = mysql_query($sql,$conn) or die("Query Failed..
" . mysql_error());
if(!$results)
{
$message = "Bad Query !";
$this->error($message);
return false;
}
if(!(eregi("^select",$sql) || eregi("^show",$sql)))
{
return true;
}
else
{
$count = 0;
$data = array();
while($row = mysql_fetch_array($results))
{
$data[$count] = $row;
$count++;
}
mysql_free_result($results);
return $data;
}
}
}
$obj = new myclass();
$obj->sql_query("");