Browse Source

Raw placeholder name, -forced LIMIT, +lastquery

dev
colshrapnel 13 years ago
parent
commit
83d9f8e979
  1. 20
      safemysql.class.php

20
safemysql.class.php

@ -2,7 +2,9 @@
class SafeMySQL class SafeMySQL
{ {
private $conn; public $lastquery;
private $conn;
private $emode; private $emode;
private $exname; private $exname;
@ -77,10 +79,6 @@ class SafeMySQL
public function getOne() public function getOne()
{ {
$query = $this->prepareQuery(func_get_args()); $query = $this->prepareQuery(func_get_args());
if ( !preg_match('~LIMIT\s+\d+\s*(,\s*\d+\s*)?$~', $query) )
{
$query .= " LIMIT 1";
}
if ($res = $this->rawQuery($query)) if ($res = $this->rawQuery($query))
{ {
$row = $this->fetch($res); $row = $this->fetch($res);
@ -95,11 +93,6 @@ class SafeMySQL
public function getRow() public function getRow()
{ {
$query = $this->prepareQuery(func_get_args()); $query = $this->prepareQuery(func_get_args());
if ( !preg_match('~LIMIT\s+\d+\s*(,\s*\d+\s*)?$~',$query) )
{
$query.= " LIMIT 1";
}
if ($res = $this->rawQuery($query)) { if ($res = $this->rawQuery($query)) {
$ret = $this->fetch($res); $ret = $this->fetch($res);
$this->free($res); $this->free($res);
@ -204,7 +197,9 @@ class SafeMySQL
return $input; return $input;
} }
private function rawQuery($query) { private function rawQuery($query)
{
$this->lastquery = $query;
$res = mysqli_query($this->conn, $query) or $this->error(mysqli_error($this->conn).". Full query: [$query]"); $res = mysqli_query($this->conn, $query) or $this->error(mysqli_error($this->conn).". Full query: [$query]");
return $res; return $res;
} }
@ -257,7 +252,7 @@ class SafeMySQL
$value = '?'; $value = '?';
$qmarks++; $qmarks++;
break; break;
case '?q': case '?p':
break; break;
default: default:
$this->error("Unknown placeholder type ($pholder) in [$raw]"); $this->error("Unknown placeholder type ($pholder) in [$raw]");
@ -265,7 +260,6 @@ class SafeMySQL
$query = substr_replace($query,$value,$offset,2); $query = substr_replace($query,$value,$offset,2);
$shift+= strlen($value) - strlen($pholder); $shift+= strlen($value) - strlen($pholder);
} }
$this->lastquery = $query;
return $query; return $query;
} }

Loading…
Cancel
Save