|
|
i'm new to php/mysql and i build a simple blog from scratch following dreamwear
tutorials. recently my site was shut down by my webhost because a script i
wrote maxed out php and crashed the mysql server. there is an error in an
insert transaction script. here is the script:
// Load the common classes
require_once('../includes/common/KT_common.php');
// Load the tNG classes
require_once('../includes/tng/tNG.inc.php');
// Make a transaction dispatcher instance
$tNGs = new tNG_dispatcher("../");
// Make unified connection variable
$conn_connBlog = new KT_connection($connBlog, $database_connBlog);
// Start trigger
$formValidation = new tNG_FormValidation();
$tNGs->prepareValidation($formValidation);
// End trigger
//start Trigger_ImageUpload trigger
//remove this line if you want to edit the code by hand
function Trigger_ImageUpload(&$tNG) {
$uploadObj = new tNG_ImageUpload($tNG);
$uploadObj->setFormFieldName("image_art");
$uploadObj->setDbFieldName("image_art");
$uploadObj->setFolder("../img/blog_img/");
$uploadObj->setResize("true", 500, 0);
$uploadObj->setMaxSize(200);
$uploadObj->setAllowedExtensions("gif, jpg, jpe, jpeg, png");
$uploadObj->setRename("auto");
return $uploadObj->Execute();
}
//end Trigger_ImageUpload trigger
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "",
$theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ?
mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" :
"NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_connBlog, $connBlog);
$query_rsArticles = "SELECT * FROM blg_article_art ORDER BY date_art DESC";
$rsArticles = mysql_query($query_rsArticles, $connBlog) or die(mysql_error());
$row_rsArticles = mysql_fetch_assoc($rsArticles);
$totalRows_rsArticles = mysql_num_rows($rsArticles);
// Make an insert transaction instance
$ins_blg_article_art = new tNG_insert($conn_connBlog);
$tNGs->addTransaction($ins_blg_article_art);
// Register triggers
$ins_blg_article_art->registerTrigger("STARTER", "Trigger_Default_Starter", 1,
"POST", "KT_Insert1");
$ins_blg_article_art->registerTrigger("BEFORE",
"Trigger_Default_FormValidation", 10, $formValidation);
$ins_blg_article_art->registerTrigger("END", "Trigger_Default_Redirect", 99,
"list_art.php");
$ins_blg_article_art->registerTrigger("AFTER", "Trigger_ImageUpload", 97);
// Add columns
$ins_blg_article_art->setTable("blg_article_art");
$ins_blg_article_art->addColumn("title_art", "STRING_TYPE", "POST",
"title_art");
$ins_blg_article_art->addColumn("text_art", "STRING_TYPE", "POST", "text_art");
$ins_blg_article_art->addColumn("date_art", "DATE_TYPE", "POST", "date_art",
"{NOW_DT}");
$ins_blg_article_art->addColumn("image_art", "FILE_TYPE", "FILES",
"image_art");
$ins_blg_article_art->setPrimaryKey("id_art", "NUMERIC_TYPE");
// Execute all the registered transactions
$tNGs->executeTransactions();
// Get the transaction recordset
$rsblg_article_art = $tNGs->getRecordset("blg_article_art");
$row_rsblg_article_art = mysql_fetch_assoc($rsblg_article_art);
$totalRows_rsblg_article_art = mysql_num_rows($rsblg_article_art);
can anyone see anything wrong here?
|
|