note 63095 added to function.mysql-real-escape-string

From: Date: Mon, 13 Mar 2006 11:23:49 +0000
Subject: note 63095 added to function.mysql-real-escape-string
Groups: php.notes 
Request: Send a blank email to php-notes+get-105706@lists.php.net to get a copy of this message
Here's my version, this replaces empty strings with NULLs instead of using a quoted empty string which was causing a sql error when adding empty values to an integer column which allows nulls. Your mileage may vary. <?php function quote_smart($value) { if (get_magic_quotes_gpc()) $value = stripslashes($value); if($value == '') $value = 'NULL'; else if (!is_numeric($value) || $value[0] == '0') $value = "'" . mysql_real_escape_string($value) . "'"; //Quote if not integer return $value; } ?> ---- Server IP: 84.18.202.180 Probable Submitter: 82.109.80.217 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.mysql-real-escape-string.php Edit -- http://master.php.net/note/edit/63095 Del: integrated -- http://master.php.net/note/delete/63095/integrated Del: useless -- http://master.php.net/note/delete/63095/useless Del: bad code -- http://master.php.net/note/delete/63095/bad+code Del: spam -- http://master.php.net/note/delete/63095/spam Del: non-english -- http://master.php.net/note/delete/63095/non-english Del: in docs -- http://master.php.net/note/delete/63095/in+docs Del: other reasons-- http://master.php.net/note/delete/63095 Reject -- http://master.php.net/note/reject/63095 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#105706) next »