Formatear valor de cadena para sql con php
Función con la que podemos formatear el valor de una cadena con php para la correcta utilización de consultas en sql, se trata de una función utilizada desde hace mucho tiempo para asegurar un correcto funcionamiento en las consultas mysql y msqli:
Editado
<?php 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; } echo GetSQLValueString("Hay 2 monos en el arbol","text"); ?>
Editado
0
Puntos
Puntos
8235
Visitas
Visitas
0
Resp
Resp
Por alber hace 103 meses
Administrador