Copy CodeThe code is as follows:
/*
*@ Adding data functions automatically
*@ $table Table Name
*@ $arr Word Snippets Array ("title", Array ("content", int))
*@ Array (field, type)
*@ type description
html--Allow HTML
unhtml-HTML is not allowed
int--int Type
Float--Float type
*/
automatically inserting data functions
function AutoInsert ($table, $arr =array (), $method = ' post ')
{
$sql = "INSERT INTO". Db_tblpre. " $table set ";
$var = "";
Print_r ($arr);
if (empty ($arr)) $arr =$_post?$_post:$_get;
if (empty ($arr)) return false;
$ct =count ($arr)-1;
foreach ($arr as $k = $v)
{
$vtype = "unhtml";
if (Is_array ($v))
{
$vtype =@ $v [1];
$v = $v [0];
}
if ($method = = ' Post ')
{
$_post[$v]=isset ($_post[$v]) trim ($_post[$v]): "";
if (Is_int ($_post[$v]))
{
$_post[$v]=intval ($_post[$v]);
}elseif (Is_float ($_post[$v]))
{
$_post[$v]=floatval ($_post[$v]);
}elseif (is_string ($_post[$v]))
{
equals 1 to save HTML by default does not save HTML
if ($vtype = = "Unhtml")
{
$_post[$v]=htmlspecialchars ($_post[$v]);
}elseif ($vtype = = "int")
{
$_post[$v]= @intval ($_post[$v]);
}elseif ($vtype = = ' float ')
{
$_post[$v]= @floatval ($_post[$v]);
}
}
$var. = "$v = ' $_post[$v] '". ($k < $ct? ",": ");
}else
{
$_get[$v]=isset ($_get[$v]) trim ($_get[$v]): "";
if (Is_int ($_get[$v]))
{
$_get[$v]=intval ($_get[$v]);
}elseif (Is_float ($_get[$v]))
{
$_get[$v]=floatval ($_get[$v]);
}elseif (is_string ($_get[$v]))
{
equals 1 to save HTML by default does not save HTML
if ($vtype = = ' unhtml ')
{
$_get[$v]=htmlspecialchars ($_get[$v]);
}elseif ($vtype = = ' int ')
{
$_get[$v]=intval ($_get[$v]);
}elseif ($vtype = = ' float ')
{
$_get[$v]=floatval ($_get[$v]);
}
}
$var. = "$v = ' $_get[$v] '". ($k < $ct? ",": ");
}
}
$sql. = $var;
$this->query ($sql);
return $this->insert_id ();
}
/**
@ Auto Update data function
*@ $table Table Name
*@ $arr Word Snippets Array ("title", Array ("content", int))
*@ Array (field, type)
*@ type description
html--Allow HTML
unhtml-HTML is not allowed
int--int Type
Float--Float type
* * $where condition array type same as $arr
* How to $method form submission
*/
function AutoUpdate ($table, $arr =array (), $where =array (), $method = ' post ')
{
$sql = "Update". Db_tblpre. " $table set ";
$var = $w = "";
if (empty ($arr)) $arr =$_post?$_post:$_get;
if (empty ($arr)) return false;
$ct =count ($arr)-1;
foreach ($arr as $k = $v)
{
$vtype = "unhtml";
if (Is_array ($v))
{
$vtype =@ $v [1];
$v = $v [0];
}
if ($method = = ' Post ')
{
$_post[$v]=isset ($_post[$v]) trim ($_post[$v]): "";
if (Is_int ($_post[$v]))
{
$_post[$v]=intval ($_post[$v]);
}elseif (Is_float ($_post[$v]))
{
$_post[$v]=floatval ($_post[$v]);
}elseif (is_string ($_post[$v]))
{
equals 1 to save HTML by default does not save HTML
if ($vtype = = "Unhtml")
{
$_post[$v]=htmlspecialchars ($_post[$v]);
}elseif ($vtype = = "int")
{
$_post[$v]= @intval ($_post[$v]);
}elseif ($vtype = = ' float ')
{
$_post[$v]= @floatval ($_post[$v]);
}
}
$var. = "$v = ' $_post[$v] '". ($k < $ct? ",": ");
}else
{
$_get[$v]=isset ($_get[$v]) trim ($_get[$v]): "";
if (Is_int ($_get[$v]))
{
$_get[$v]=intval ($_get[$v]);
}elseif (Is_float ($_get[$v]))
{
$_get[$v]=floatval ($_get[$v]);
}elseif (is_string ($_get[$v]))
{
equals 1 to save HTML by default does not save HTML
if ($vtype = = ' unhtml ')
{
$_get[$v]=htmlspecialchars ($_get[$v]);
}elseif ($vtype = = ' int ')
{
$_get[$v]=intval ($_get[$v]);
}elseif ($vtype = = ' float ')
{
$_get[$v]=floatval ($_get[$v]);
}
}
$var. = "$v = ' $_get[$v] '". ($k < $ct? ",": ");
}
}
$sql. = $var;
Parse where
$ct =count ($where)-1;
if (!empty ($where)) $w = "where";
foreach ($where as $k = $v)
{
$vtype = "unhtml";
if (Is_array ($v))
{
$vtype =@ $v [1];
$v = $v [0];
}
if ($method = = ' Post ')
{
$_post[$v]=isset ($_post[$v]) trim ($_post[$v]): "";
if (Is_int ($_post[$v]))
{
$_post[$v]=intval ($_post[$v]);
}elseif (Is_float ($_post[$v]))
{
$_post[$v]=floatval ($_post[$v]);
}elseif (is_string ($_post[$v]))
{
equals 1 to save HTML by default does not save HTML
if ($vtype = = "Unhtml")
{
$_post[$v]=htmlspecialchars ($_post[$v]);
}elseif ($vtype = = "int")
{
$_post[$v]= @intval ($_post[$v]);
}elseif ($vtype = = ' float ')
{
$_post[$v]= @floatval ($_post[$v]);
}
}
$w. = "$v = ' $_post[$v] '". ($k < $ct? "and": ");
}else
{
$_get[$v]=isset ($_get[$v]) trim ($_get[$v]): "";
if (Is_int ($_get[$v]))
{
$_get[$v]=intval ($_get[$v]);
}elseif (Is_float ($_get[$v]))
{
$_get[$v]=floatval ($_get[$v]);
}elseif (is_string ($_get[$v]))
{
equals 1 to save HTML by default does not save HTML
if ($vtype = = ' unhtml ')
{
$_get[$v]=htmlspecialchars ($_get[$v]);
}elseif ($vtype = = ' int ')
{
$_get[$v]=intval ($_get[$v]);
}elseif ($vtype = = ' float ')
{
$_get[$v]=floatval ($_get[$v]);
}
}
$w. = "$v = ' $_get[$v] '". ($k < $ct? "and": ");
}
}
$sql. = $w;
$this->query ($sql);
}
http://www.bkjia.com/PHPjc/323747.html www.bkjia.com true http://www.bkjia.com/PHPjc/323747.html techarticle Copy the code as follows:/* *@ automatically add data function *@ $table table name *@ $arr Word Snippets Array ("title", Array ("content", int)) *@ Array (field, type) *@ type description html--allow HT ...