Hi NogDog
Thanks for responding - don't think the code will help with this problem but here it is:
This is the class method which creates the SQL statement then calla a separate class method to run it:
// amend table data from an array or stdClass object - only where data modified
public function TableAmend($tableName, $recordID, $dataSource, $modified)
{
// initialise properties
$this->_arData = $dataSource;
$this->_arModified = $modified;
$this->_rowID = $recordID;
$this->_table = $tableName;
// begin statement with all-tables administrative field identifier
$stmt = "UPDATE $this->_table SET amender = '$this->_user', ";
// each input form value - where field value has been amended - absent value stored as NULL,
// otherwise store entered values
foreach($this->_arData as $field => $value)
if($this->_arModified[$field])
if($value == "")
$stmt .= "$field = NULL, ";
else
$stmt .= "$field = '$value', ";
// remove last comma and space
$stmt = substr($stmt, 0, strlen($stmt)-2);
// complete statement with record identifier
$stmt .= " WHERE id = $recordID";
// run SQL query
$result = $this->dBLink()->Query($stmt);
return $result;
}
In a test run the above code produces the following SQL statement:
UPDATE inter_address SET amender = 'mark', street = '5 The Street' WHERE id = 155
$this->dBLink()->Query($stmt)
is a class method to initialise a separate class method utilised for SQL interaction with the database - as:
// run a dB query utilising the SQL statement passed as an argument
public function Query($sql)
{
// clear any previous query result data
$this->_resultRows = $this->_resultSet = $return_array = NULL;
// store result set in member variable
$this->_resultSet = $this->_linkIdent->query($sql);
// where result set created, store each record of result set as an object in an array member
if(!is_bool($this->_resultSet))
{
// until end of result records -
while($obj = $this->_resultSet->fetch_object())
$return_array[] = $obj;
$this->_resultRows = $return_array;
return 1;
}
// where no result set
else
return 0;
}
As stated in the original posting the above code produces a valid SQL statement:
UPDATE inter_address SET amender = 'mark', street = '5 The Street' WHERE id = 155
which works when pasted into a mysql client or when is pased into the original code eg.
// remove last comma and space
$stmt = substr($stmt, 0, strlen($stmt)-2);
// complete statement with record identifier
$stmt .= " WHERE id = $recordID";
// copy of generated statement passed to method for execution - THIS WORKS!!
$stmt = "UPDATE inter_address SET amender = 'mark', street = '5 The Street' WHERE id = 155";
// run SQL query
$result = $this->dBLink()->Query($stmt);
This is why I'm not sure if the code is helpful - the SQL statement is valid but doesn't work when passed directly to the SQL execution class method - but does when a copy of it is passed - that's what's got me baffled.
Hope this helps
Mark