I have learned a lot with the last class I worked on, and it works great! But I am trying to understand how to do mysql querys with a class. I know the database connection part works fine, but I have two problems.
class Jazit_Database_Class
{
// Database Connect & Query Variables
var $J_DB_Host;
var $J_DB_User;
var $J_DB_Pass;
var $J_DB_Database;
var $J_Query;
var $New_Query_1;
var $num;
var $row;
function Jazit_DB_Connect($J_DB_Host,$J_DB_User,$J_DB_Pass,$J_DB_Database)
{
// Connect to Database
$this->$link=mysql_connect("$J_DB_Host","$J_DB_User","$J_DB_Pass");
if(!$this->$link)die("Failed Connecting to $J_DB_Database");
mysql_select_db("$J_DB_Database") or die("Could not open database");
}
function Jazit_Query_1($J_Query)
{
// Query the Database
$this->$New_Query_1=mysql_query("$J_Query");
$this->$num=mysql_num_rows($this->$New_Query_1);
while($this->$row = mysql_fetch_array($this->$New_Query_1)) {
echo $this->$row["UserName"];
echo $this->$row["UserPass"];
}
}
}
// Code to Display
$MySql_Connect = new Jazit_Database_Class;
$MySql_Connect->Jazit_DB_Connect("localhost","jazbot","Jzb80032","jazbot");
$MySql_Connect->Jazit_Query_1("SELECT * FROM Orders");
First of all, I get an error saying line 30 is not a valid mysql result resource. Line 30 is
$this->$num=mysql_num_rows($this->$New_Query_1);
Second, right now the echo of the query results is in the class... how would I use them outside of the class?