So here is my first question. In order to access any functions or properties within a PHP class I need to use the $this-> operator right?
So then I have 2 PHP files
Below is mysqlbuilder.php this file is for building queries and stuff like that. If I am reinventing the wheel please let me know. Basically the one function in there takes in a table name and an array of colums and turns it into the begining of an INSERT Statement.
<?php
function startInsert($table, $colums)
{
$cols = "(";
foreach($colums as $col)
{
$end = end($colums);
if($col == $end)
{
$cols .= $col.")";
}//end if
else
{
$cols .= $col.", ";
}//end else
}//end foreach colums
$ret = "INSERT INTO $table";
$ret .= $cols;
}//end startInsert
?>
My second file Customer.php this file is a representation of table in a database, in an object. Basically it is for easy access and storage of DB entries.
<?php
include("mysqlbuilder.php");
class Customer
{
var $id;
var $western_id;
var $name;
var $address;
var $phone;
var $email;
var $columns = array("western_id", "name", "address", "phone", "email");
var $table_name = "customers";
function Customer($id = 0, $western_id = "stu000000", $name = "", $address = "", $phone = "", $email = "")
{
$this->id = $id;
$this->western_id = $western_id;
$this->name = $name;
$this->address = $address;
$this->phone = $phone;
$this->email = $email;
}//end constructor
private function buildValues()
{
return "values('$this->western_id', '$this->name', '$this->address', '$this->phone', '$this->email');";
}//end buildValues
function buildInsert()
{
$ret = startInsert($this->table_name, $this->columns);
echo $ret."<br />";
$ret .= $this->buildValues();
echo $ret;
}//end buildInsert
}//end class
$cust = new Customer();
$cust->buildInsert();
?>
My main problem is with the buildInsert fuction. First off when I use the startInsert function from mysqlbuilder.php. The problem is it returns nothing.
Can anyone help me figure out why this is not working the way I want it too. If it was working properly the output would contain a complete INSERT querey.