From 9766f0152b3174ceb4a572dc71fb9e7cd129cdd4 Mon Sep 17 00:00:00 2001
From: colshrapnel
Date: Thu, 31 Jan 2013 16:32:20 +0400
Subject: [PATCH] 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.
---
safemysql.class.php | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/safemysql.class.php b/safemysql.class.php
index 4a2ed2a..5dc1cb1 100644
--- a/safemysql.class.php
+++ b/safemysql.class.php
@@ -470,23 +470,28 @@ class SafeMySQL
private function escapeInt($value)
{
- if (is_float($value))
- {
- $value = number_format($value, 0, '.', ''); // may lose precision on big numbers
- }
- elseif(is_numeric($value))
+ if ($value === NULL)
{
- $value = $value;
+ return 'NULL';
}
- else
+ if(!is_numeric($value))
{
$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)
{
+ if ($value === NULL)
+ {
+ return 'NULL';
+ }
return "'".mysqli_real_escape_string($this->conn,$value)."'";
}