Hello
This is a example of code generating by a product for MySQL database .
This code is a good example of PHP DAO's to automate the development of applications with PHP and MySQL.
More information :
http://www.mentattech.com
/**
* getRecords-method. This will read all contents from database table and
* build a Collection containing valueObjects. Please note, that this method
* will consume huge amounts of resources if table has lot's of rows.
* This should only be used when target tables have only small amounts
* of data.
* The collection has similar methods such as a Java Collection (i.e. HashMap,
* Collection, HashTable, etc).
* @param $collObject Collection passed by the Logic Layer to wrap the
* result set.
*
*/
*/
function getRecords(&$collObject) {
$sql = "SELECT * FROM nuke_comments ";
$sql = $sql."ORDER BY pn_tid ";
$searchResults = $this->listQuery($sql);
if($searchResults != false) {
$collObject = $searchResults;
return true;
}
return false;
}
/**
* insRecord-method. This will create new row in database according to supplied
* valueObject contents. Make sure that values for all NOT NULL columns are
* correctly specified. Also, if this table does not use automatic surrogate-keys
* the primary-key must be specified. After INSERT command this method will
* read the generated primary-key back to valueObject if automatic surrogate-keys
* were used.
*
* @param valueObject This parameter contains the class instance to be created.
* If automatic surrogate-keys are not used the Primary-key
* field must be set for this to work properly.
*/
function insRecord(&$valueObject) {
$sql = "INSERT INTO nuke_comments ";
$sql = $sql."( ";
$sql = $sql." pn_tid, ";
$sql = $sql." pn_pid, ";
$sql = $sql." pn_sid, ";
$sql = $sql." pn_date, ";
$sql = $sql." pn_name, ";
$sql = $sql." pn_email, ";
$sql = $sql." pn_url, ";
$sql = $sql." pn_host_name, ";
$sql = $sql." pn_subject, ";
$sql = $sql." pn_comment, ";
$sql = $sql." pn_score, ";
$sql = $sql." pn_reason";
$sql = $sql." )";
$sql = $sql." VALUES (";
$sql = $sql."'".$valueObject->getpn_tid()."', ";
$sql = $sql."'".$valueObject->getpn_pid()."', ";
$sql = $sql."'".$valueObject->getpn_sid()."', ";
$sql = $sql."'".$valueObject->getpn_date()."', ";
$sql = $sql."'".$valueObject->getpn_name()."', ";
$sql = $sql."'".$valueObject->getpn_email()."', ";
$sql = $sql."'".$valueObject->getpn_url()."', ";
$sql = $sql."'".$valueObject->getpn_host_name()."', ";
$sql = $sql."'".$valueObject->getpn_subject()."', ";
$sql = $sql."'".$valueObject->getpn_comment()."', ";
$sql = $sql."'".$valueObject->getpn_score()."', ";
$sql = $sql."'".$valueObject->getpn_reason()."' ";
$sql = $sql.") ";
$result = $this->execute($sql);
if ($result != true) {
return false;
}
return true;
}
/**
* updRecord-method. This method will save the current state of valueObject to database.
* Save can not be used to create new instances in database, so upper layer must
* make sure that the primary-key is correctly specified. Primary-key will indicate
* which instance is going to be updated in database.
*
* @param valueObject This parameter contains the class instance to be saved.
* Primary-key field must be set for this to work properly.
*/
function updRecord($valueObject) {
$sql = "UPDATE nuke_comments SET ";
$sql = $sql." pn_tid = ".$valueObject->getpn_tid().",";
$sql = $sql." pn_pid = ".$valueObject->getpn_pid().",";
$sql = $sql." pn_sid = ".$valueObject->getpn_sid().",";
$sql = $sql." pn_date = ".$valueObject->getpn_date().",";
$sql = $sql." pn_name = ".$valueObject->getpn_name().",";
$sql = $sql." pn_email = ".$valueObject->getpn_email().",";
$sql = $sql." pn_url = ".$valueObject->getpn_url().",";
$sql = $sql." pn_host_name = ".$valueObject->getpn_host_name().",";
$sql = $sql." pn_subject = ".$valueObject->getpn_subject().",";
$sql = $sql." pn_comment = ".$valueObject->getpn_comment().",";
$sql = $sql." pn_score = ".$valueObject->getpn_score().",";
$sql = $sql." pn_reason = ".$valueObject->getpn_reason()." ";
$sql = $sql." WHERE pn_tid = ".$valueObject->getpn_tid();
$result = $this->execute($sql);
if ($result != 1) {
return false;
}
else {
return true;
}
}
/**
* delRecord-method. This method will remove the information from database as identified by
* by primary-key in supplied valueObject. Once valueObject has been deleted it can not
* be restored by calling save. Restoring can only be done using create method but if
* database is using automatic surrogate-keys, the resulting object will have different
* primary-key than what it was in the deleted object.
*
* @param valueObject This parameter contains the class instance to be deleted.
* Primary-key field must be set for this to work properly.
*/
function delRecord($valueObject) {
$sql = "DELETE FROM nuke_comments";
$sql = $sql." WHERE pn_tid = ".$valueObject->getpn_tid();
$result = $this->execute($sql);
if ($result != 1) {
return false;
}
return true;
}
/**
* @param id This parameter contains the record ID to be deleted.
* Its value must be the Primary-key field value.
*/
function delRecordId($pn_tidIn) {
$sql = "DELETE FROM nuke_comments WHERE pn_tid = ".$pn_tidIn;
$result = $this->execute($sql);
if ($result != 1) {
return false;
}
return true;
}
+------------------------------------------------------+
Kind Regards