Browse Source

Merge pull request #1 from fixxxerrr/master

Placeholder collision fix proposal
dev
colshrapnel 13 years ago
parent
commit
8606543e87
  1. 25
      safemysql.class.php

25
safemysql.class.php

@ -46,10 +46,9 @@ class SafeMySQL
public function query() public function query()
{ {
$query = $this->prepareQuery(func_get_args()); return $this->rawQuery($this->prepareQuery(func_get_args()));
$res = mysqli_query($this->conn, $query) or $this->error(mysqli_error($this->conn).". Full query: [$query]");
return $res;
} }
public function fetch($result,$mode=self::RESULT_ASSOC) public function fetch($result,$mode=self::RESULT_ASSOC)
{ {
return mysqli_fetch_array($result, $mode); return mysqli_fetch_array($result, $mode);
@ -82,7 +81,7 @@ class SafeMySQL
{ {
$query .= " LIMIT 1"; $query .= " LIMIT 1";
} }
if ($res = $this->query($query)) if ($res = $this->rawQuery($query))
{ {
$row = $this->fetch($res); $row = $this->fetch($res);
if (is_array($row)) { if (is_array($row)) {
@ -101,7 +100,7 @@ class SafeMySQL
$query.= " LIMIT 1"; $query.= " LIMIT 1";
} }
if ($res = $this->query($query)) { if ($res = $this->rawQuery($query)) {
$ret = $this->fetch($res); $ret = $this->fetch($res);
$this->free($res); $this->free($res);
return $ret; return $ret;
@ -113,7 +112,7 @@ class SafeMySQL
{ {
$ret = array(); $ret = array();
$query = $this->prepareQuery(func_get_args()); $query = $this->prepareQuery(func_get_args());
if ( $res = $this->query($query) ) if ( $res = $this->rawQuery($query) )
{ {
while($row = $this->fetch($res)) while($row = $this->fetch($res))
{ {
@ -128,7 +127,7 @@ class SafeMySQL
{ {
$ret = array(); $ret = array();
$query = $this->prepareQuery(func_get_args()); $query = $this->prepareQuery(func_get_args());
if ( $res = $this->query($query) ) if ( $res = $this->rawQuery($query) )
{ {
while($row = $this->fetch($res)) while($row = $this->fetch($res))
{ {
@ -146,7 +145,7 @@ class SafeMySQL
$query = $this->prepareQuery($args); $query = $this->prepareQuery($args);
$ret = array(); $ret = array();
if ( $res = $this->query($query) ) if ( $res = $this->rawQuery($query) )
{ {
while($row = $this->fetch($res)) while($row = $this->fetch($res))
{ {
@ -164,7 +163,7 @@ class SafeMySQL
$query = $this->prepareQuery($args); $query = $this->prepareQuery($args);
$ret = array(); $ret = array();
if ( $res = $this->query($query) ) if ( $res = $this->rawQuery($query) )
{ {
while($row = $res->fetch($res)) while($row = $res->fetch($res))
{ {
@ -204,6 +203,12 @@ class SafeMySQL
} }
return $input; return $input;
} }
private function rawQuery($query) {
$res = mysqli_query($this->conn, $query) or $this->error(mysqli_error($this->conn).". Full query: [$query]");
return $res;
}
private function prepareQuery($args) private function prepareQuery($args)
{ {
$raw = $query = array_shift($args); $raw = $query = array_shift($args);
@ -252,6 +257,8 @@ class SafeMySQL
$value = '?'; $value = '?';
$qmarks++; $qmarks++;
break; break;
case '?q':
break;
default: default:
$this->error("Unknown placeholder type ($pholder) in [$raw]"); $this->error("Unknown placeholder type ($pholder) in [$raw]");
} }

Loading…
Cancel
Save