#native_company# #native_desc#
#native_cta#

sql_parse()

By Christian Dechery
on April 2, 2001

Version: 1.0

Type: Function

Category: Databases

License: GNU General Public License

Description: small but usefull function to parse a var to be valid in a sql query-string.

function sql_parse($field,$is_string=0)
{
	if(strlen(trim($field))==0)
		return "null";
	if($is_string)
	{
		$field=chop($field);
		$field=str_replace("'","''",$field);
		$field="'".$field."'";
	}
	return trim($field);
}

// so a query would look like this
// $id=sql_parse($id); $name=sql_parse($name); $phone_number=sql_parse($phone_number);
// $query = "insert into table1(id,name,phone_number) values ($id,$name,$phone_number)";