Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove redundant code and fix phpDoc #55

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 32 additions & 50 deletions safemysql.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function __construct($opt = array())
*
* @param string $query - an SQL query with placeholders
* @param mixed $arg,... unlimited number of arguments to match placeholders in the query
* @return resource|FALSE whatever mysqli_query returns
* @return mysql_result|true whatever mysqli_query returns
*/
public function query()
{
Expand All @@ -145,7 +145,7 @@ public function query()
*
* @param resource $result - myqli result
* @param int $mode - optional fetch mode, RESULT_ASSOC|RESULT_NUM, default RESULT_ASSOC
* @return array|FALSE whatever mysqli_fetch_array returns
* @return array|null whatever mysqli_fetch_array returns
*/
public function fetch($result,$mode=self::RESULT_ASSOC)
{
Expand Down Expand Up @@ -204,14 +204,11 @@ public function free($result)
*/
public function getOne()
{
$query = $this->prepareQuery(func_get_args());
if ($res = $this->rawQuery($query))
{
$row = $this->fetch($res);
if (is_array($row)) {
return reset($row);
}
$this->free($res);
$res = $this->rawQuery($this->prepareQuery(func_get_args()));
$row = $this->fetch($res);
$this->free($res);
if (is_array($row)) {
return reset($row);
}
return FALSE;
}
Expand All @@ -225,17 +222,14 @@ public function getOne()
*
* @param string $query - an SQL query with placeholders
* @param mixed $arg,... unlimited number of arguments to match placeholders in the query
* @return array|FALSE either associative array contains first row of resultset or FALSE if none found
* @return array|null either associative array contains first row of resultset or NULL if none found
*/
public function getRow()
{
$query = $this->prepareQuery(func_get_args());
if ($res = $this->rawQuery($query)) {
$ret = $this->fetch($res);
$this->free($res);
return $ret;
}
return FALSE;
$res = $this->rawQuery($this->prepareQuery(func_get_args()));
$ret = $this->fetch($res);
$this->free($res);
return $ret;
}

/**
Expand All @@ -252,15 +246,12 @@ public function getRow()
public function getCol()
{
$ret = array();
$query = $this->prepareQuery(func_get_args());
if ( $res = $this->rawQuery($query) )
$res = $this->rawQuery($this->prepareQuery(func_get_args()));
while ($row = $this->fetch($res))
{
while($row = $this->fetch($res))
{
$ret[] = reset($row);
}
$this->free($res);
$ret[] = reset($row);
}
$this->free($res);
return $ret;
}

Expand All @@ -277,16 +268,13 @@ public function getCol()
*/
public function getAll()
{
$ret = array();
$query = $this->prepareQuery(func_get_args());
if ( $res = $this->rawQuery($query) )
$ret = array();
$res = $this->rawQuery($this->prepareQuery(func_get_args()));
while ($row = $this->fetch($res))
{
while($row = $this->fetch($res))
{
$ret[] = $row;
}
$this->free($res);
$ret[] = $row;
}
$this->free($res);
return $ret;
}

Expand All @@ -306,17 +294,14 @@ public function getInd()
{
$args = func_get_args();
$index = array_shift($args);
$query = $this->prepareQuery($args);

$ret = array();
if ( $res = $this->rawQuery($query) )
$res = $this->rawQuery($this->prepareQuery($args));
while ($row = $this->fetch($res))
{
while($row = $this->fetch($res))
{
$ret[$row[$index]] = $row;
}
$this->free($res);
$ret[$row[$index]] = $row;
}
$this->free($res);
return $ret;
}

Expand All @@ -335,19 +320,16 @@ public function getIndCol()
{
$args = func_get_args();
$index = array_shift($args);
$query = $this->prepareQuery($args);

$ret = array();
if ( $res = $this->rawQuery($query) )
$res = $this->rawQuery($this->prepareQuery($args));
while ($row = $this->fetch($res))
{
while($row = $this->fetch($res))
{
$key = $row[$index];
unset($row[$index]);
$ret[$key] = reset($row);
}
$this->free($res);
$key = $row[$index];
unset($row[$index]);
$ret[$key] = reset($row);
}
$this->free($res);
return $ret;
}

Expand Down Expand Up @@ -458,7 +440,7 @@ public function getStats()
* also logs some stats like profiling info and error message
*
* @param string $query - a regular SQL query
* @return mysqli result resource or FALSE on error
* @return mysqli_result|true result or true if query not provides a result
*/
protected function rawQuery($query)
{
Expand Down