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. 19
      safemysql.class.php

19
safemysql.class.php

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

Loading…
Cancel
Save