note 63095 deleted from function.mysql-real-escape-string by danbrown
| From: | danbrown@php.net | Date: | Sat, 14 Mar 2009 15:10:00 +0000 |
| Subject: | note 63095 deleted from function.mysql-real-escape-string by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-151937@lists.php.net to get a copy of this message | ||
Note Submitter: keith dot lawrence at jpmh dot co dot uk
----
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;
}
?>