Browse Source

Added NULL translation as suggested in issue #11

I changed my mind and made added literal translation from PHP's NULL into Mysql's NULL when processing placeholders. Thanks to @ExplodingCabbage for the perfect reasoning.
dev
colshrapnel 12 years ago
parent
commit
9766f0152b
  1. 21
      safemysql.class.php

21
safemysql.class.php

@ -470,23 +470,28 @@ class SafeMySQL
private function escapeInt($value) private function escapeInt($value)
{ {
if (is_float($value)) if ($value === NULL)
{
$value = number_format($value, 0, '.', ''); // may lose precision on big numbers
}
elseif(is_numeric($value))
{ {
$value = $value; return 'NULL';
} }
else if(!is_numeric($value))
{ {
$this->error("Integer (?i) placeholder expects numeric value, ".gettype($value)." given"); $this->error("Integer (?i) placeholder expects numeric value, ".gettype($value)." given");
return FALSE;
} }
return " ".$value; // to avoid double munus collision (one from query + one from value = comment --) if (is_float($value))
{
$value = number_format($value, 0, '.', ''); // may lose precision on big numbers
}
return $value;
} }
private function escapeString($value) private function escapeString($value)
{ {
if ($value === NULL)
{
return 'NULL';
}
return "'".mysqli_real_escape_string($this->conn,$value)."'"; return "'".mysqli_real_escape_string($this->conn,$value)."'";
} }

Loading…
Cancel
Save