Hi im making this db class, well it doesnt really do anything except use mysql_functions, the reason i made this was for stored procedure purposes instead of dong it on db im using php for stored procedure,
here's my class
<?php
class db
{
//attributes
private $db_link;
private $host;
private $username;
private $password;
private $db_name;
private $num_rows;
private $result;
//constructor
function db($host,$username,$password,$db_name="")
{
$this->setHost($host);
$this->setUsername($username);
$this->setPassword($password);
if (!empty($db_name)) {
$this->selectDB($db_name);
$this->setDB();
}
}
//setters
function setHost($host)
{
$this->host = $host;
}
function setUsername($username)
{
$this->username = $username;
}
function setPassword($password)
{
$this->password = $password;
}
function connect_db()
{
$this->db_link = mysql_connect($this->getHost(),$this->getUsername(),$this->getPassword(),true) or die(mysql_error());
}
function select_db()
{
mysql_select_db($this->getDB(),$this->getLink()) or die(mysql_error());
}
function selectDB($db_name)
{
$this->db_name = $db_name;
}
function setDB()
{
$this->connect_db();
$this->select_db();
}
function setNumRows($num_rows)
{
$this->num_rows = $num_rows;
}
function setResult($result)
{
$this->result = $result;
}
//getters
function getHost()
{
return $this->host;
}
function getUsername()
{
return $this->username;
}
function getPassword()
{
return $this->password;
}
function getDB()
{
return $this->db_name;
}
function getNumRows()
{
return $this->num_rows;
}
function getResult()
{
return $this->result;
}
function getLink()
{
return $this->db_link;
}
//methods
function sql_query($query)
{
$operation = substr($query,0,6);
$result = mysql_query($query,$this->getLink()) or die(mysql_error());
if ($result) {
$this->setResult($result);
$num_rows = ($operation == "SELECT") ? mysql_num_rows($result) : mysql_affected_rows();
$this->setNumRows($num_rows);
}
return $this->getResult();
}
function sql_fetch_array()
{
return mysql_fetch_array($this->getResult());
}
function freeResult()
{
mysql_free_result($this->getResult());
}
function closeDB()
{
mysql_close($this->getLink());
}
}
?>
so far it's working fine until i came recently to this scenario
$query1 = "some query";
$db->sql_query($query1);
while($data = $db->sql_fetch_array())
{
$query2 = "another query";
$db->sql_query($query2);
//show result of my main query
echo $data['var'];
}
if i do that then the data presented is messed up but if i replaced query2 with the typical $result = mysql_query($query2); and etc. everything goes fine, im guessing something is wrong with my class? I hope someone can shed some info coz im really at a lost here... thanks!