Hi!
Im new into OOP and Im constructing a column class that extends a table class like..
class column extends table
{
var $name;
var $type;
var $rule
}
class table
{
var $primarykey
// code goes here //
}
Then I create a instance of the table-class..
$tbluser = new table("TBLUSER");
I add columns to the table..
$tbluser->user_id = new column("USER_ID","NUMBER","Mandatory");
$tbluser->telephone = new column("TELEPHONE","VARCHAR2(30)","Optional");
$tbluser->primarykey = $tbluser->column.name;
// Now the problem... I want to do this function that I call with..
$tbluser.create();
And inside the table-class I have the create function that I want to walk through all the instances of the columns class I made..more or less like:
class table
{
var $name;
function create()
{
$query = "CREATE TABLE $this->name";
while( $col = READ ALL NAMES OF ALL THE COLUMN INSTANCES CREATED)
{
$query = $query . $col->name ." ". $col-type ."\n";
}
$query = $query ."PRIMARY KEY (".$this->primarykey."));";
sqlexecute($query);
}
Im searching for a way to do that "READ ALL NAMES OF ALL THE COLUMN INSTANCES CREATED"-part if its possible. As Im new into OOP Im not sure if it can be done - I could solve it with arrays but the array-names arr_of_column[0], arr_of_column[1] doesnt make that much sense as "USER_ID", "TELEPHONE" etcetera.
If it can be done I would appreciate an answer. I also would like (but not appreciate) to be informed if it cant be done :-(
Thanks, Niklas Andersson