Current location: Hot Scripts Forums » Advertising Forums » General Advertisements » Generating PHP code for MySQL


Generating PHP code for MySQL

Reply
  #1 (permalink)  
Old 02-03-04, 08:23 AM
ptesone ptesone is offline
Newbie Coder
 
Join Date: Dec 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Lightbulb Generating PHP code for MySQL

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
Reply With Quote
  #2 (permalink)  
Old 02-03-04, 08:26 AM
YourPHPPro's Avatar
YourPHPPro YourPHPPro is offline
Community VIP
 
Join Date: Aug 2003
Posts: 430
Thanks: 0
Thanked 0 Times in 0 Posts
Moved to advertising forum...
Reply With Quote
Reply

Bookmarks

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP code to edit a text file mdhall Script Requests 12 12-23-10 04:03 AM
PHPCode.Org - PHP Code Submission Database Dana General Advertisements 8 11-29-06 09:04 PM
convert perl code to php phptalk Perl 1 01-15-04 02:06 AM
protecting code in PHP ckb PHP 12 01-02-04 08:53 AM
php code not pulling data from DB simone PHP 1 11-22-03 02:08 AM


All times are GMT -5. The time now is 08:16 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.