Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: Jim Holden
Added: May 10, 2018 5:28 AM
Modified: May 10, 2018 5:29 AM
Views: 15
Tags: no tags
GetSQLValueString
  1. if (!function_exists("GetSQLValueString")) {
  2. function GetSQLValueString($conn,$theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  3. {
  4.   if (PHP_VERSION < 6) {
  5.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  6.   }
  7.  
  8.   $theValue = function_exists("mysqli_real_escape_string") ? mysqli_real_escape_string($conn,$theValue) : mysqli_escape_string($conn,$theValue);
  9.  
  10.   switch ($theType) {
  11.     case "text":
  12.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  13.       break;    
  14.     case "long":
  15.     case "int":
  16.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  17.       break;
  18.     case "double":
  19.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  20.       break;
  21.     case "date":
  22.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  23.       break;
  24.     case "defined":
  25.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  26.       break;
  27.   }
  28.   return $theValue;
  29. }
  30. }