GetSQLValueString - What is this function for, generated by Dreamweaver?

12 Views Asked by At

What is GetSQLValueString for? And if there is a difference for PHP7, what difference does this function make? What happens if I don't use it? Can anyone help me understand this better?

if (!function_exists("GetSQLValueString")) 
{
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
    {
        if (PHP_VERSION < 6) {
            $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;
    }
}

After that, there is a section that uses this function.

if($cod_u > 0){
        $updateSQL = sprintf("UPDATE usuario SET cod_id=%s, nome=%s, sexo=%s   WHERE cod_u=%s",
            GetSQLValueString( utf8_decode($_POST['cod_id']), "int"),
            ....
0

There are 0 best solutions below