/* 
 函数功能:根据表字段类型对字段值做相应处理
           用于构造SQL语句
    
 @theValue 参数1,值
 @theType  参数2, 值的类型
 @theDefinedValue 参数3 , 自定义类型值,默认为空
 @theNotDefinedValue 参数4 , 未定义类型值,默认为空
*/
 
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  //get_magic_quotes_gpc函数用于获取PHP 环境配置的变量 magic_quotes_gpc 
  //如果值为1则对字符做转义操作。如将'转成\'
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;  switch ($theType) {
    //text类型加上引号
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    //长整型,整型, 用intval函数获取整数值 
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    //浮点型用  doubleval做浮点处理
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    //时间类型加上引号 
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    //自定义类型则将参数3或者参数4赋值
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

解决方案 »

  1.   

    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
    {
      $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;//如果php配置没有打开magic_quotes_gpc,则将$theValue用函数转义,否则不用。  switch ($theType) {
        case "text": //表字段类型为text...
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;    
        case "long": //表字段类型为long或者...
        case "int":  //int
          $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case "double"://表字段类型为double...
          $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
          break;
        case "date":  //表字段类型为date ...
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;
        case "defined": //如果形参$theType为"defined" ...
          $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
          break;
      }
      return $theValue;
    }
      

  2.   

    1 你这个不是类,是个函数。2 来看看这篇文章你就明白这个函数是干嘛的了:
    http://blog.csdn.net/ShadowSniper/archive/2006/09/20/1250230.aspx