Commit ea1fcfbf authored by Alex Ne's avatar Alex Ne

Коректировка вводных данных

parent 897c141b
...@@ -164,10 +164,11 @@ class PDO { ...@@ -164,10 +164,11 @@ class PDO {
$SQL = "{$type} INTO `{$table}` (`" . implode('`,`', $keys) . "`) VALUES ( " . implode(", ", $pattern) . " )"; $SQL = "{$type} INTO `{$table}` (`" . implode('`,`', $keys) . "`) VALUES ( " . implode(", ", $pattern) . " )";
$statement = $this->prepare($SQL); $statement = $this->prepare($SQL);
foreach ($keys as $key) { foreach ($keys as $key) {
if (is_integer($data[$key])) { $data_bind = $this->check_value($data[$key]);
$statement->bindValue(":{$key}", $data[$key], \PDO::PARAM_INT); if (is_integer($data_bind)) {
$statement->bindValue(":{$key}", $data_bind, \PDO::PARAM_INT);
} else { } else {
$statement->bindValue(":{$key}", $data[$key], \PDO::PARAM_STR); $statement->bindValue(":{$key}", $data_bind, \PDO::PARAM_STR);
} }
} }
...@@ -209,10 +210,11 @@ class PDO { ...@@ -209,10 +210,11 @@ class PDO {
$SQL .= $whete_obj->get_sql(); $SQL .= $whete_obj->get_sql();
$statement = $this->prepare($SQL); $statement = $this->prepare($SQL);
foreach ($keys as $key) { foreach ($keys as $key) {
if (is_integer($data[$key])) { $data_bind = $this->check_value($data[$key]);
$statement->bindValue(":{$key}", $data[$key], \PDO::PARAM_INT); if (is_integer($data_bind)) {
$statement->bindValue(":{$key}", $data_bind, \PDO::PARAM_INT);
} else { } else {
$statement->bindValue(":{$key}", $data[$key], \PDO::PARAM_STR); $statement->bindValue(":{$key}", $data_bind, \PDO::PARAM_STR);
} }
} }
$whete_obj->bind($statement); $whete_obj->bind($statement);
...@@ -305,6 +307,27 @@ class PDO { ...@@ -305,6 +307,27 @@ class PDO {
} }
public function __wakeup() {} public function __wakeup() {}
/**
* @param $value
* @return mixed
*/
protected function check_value($value) {
$type = gettype($value);
switch (strtolower($type)) {
case 'boolean':
return $value ? 1 : "0";
break;
case 'null':
return "0";
break;
default:
return $value;
break;
}
}
} }
?> ?>
\ No newline at end of file
...@@ -199,12 +199,34 @@ class PDOWhereConstructor { ...@@ -199,12 +199,34 @@ class PDOWhereConstructor {
*/ */
public function bind(&$statement) { public function bind(&$statement) {
foreach ($this->data_set as $key => $data_item) { foreach ($this->data_set as $key => $data_item) {
if (is_integer($data_item)) { $data_bind = $this->check_value($data_item);
$statement->bindValue($key, $data_item, \PDO::PARAM_INT); if (is_integer($data_bind)) {
$statement->bindValue($key, $data_bind, \PDO::PARAM_INT);
} else { } else {
$statement->bindValue($key, $data_item, \PDO::PARAM_STR); $statement->bindValue($key, $data_bind, \PDO::PARAM_STR);
} }
} }
} }
/**
* @param $value
* @return mixed
*/
protected function check_value($value) {
$type = gettype($value);
switch (strtolower($type)) {
case 'boolean':
return $value ? 1 : "0";
break;
case 'null':
return "0";
break;
default:
return $value;
break;
}
}
} }
?> ?>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment