forked from Public/pics
Refactor leftover old-style arrays into new-style arrays.
This commit is contained in:
@@ -37,7 +37,7 @@ class Database
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->query('SET NAMES {string:utf8}', array('utf8' => 'utf8'));
|
||||
$this->query('SET NAMES {string:utf8}', ['utf8' => 'utf8']);
|
||||
}
|
||||
|
||||
public function getQueryCount()
|
||||
@@ -256,7 +256,7 @@ class Database
|
||||
|
||||
case 'identifier':
|
||||
// Backticks inside identifiers are supported as of MySQL 4.1. We don't need them here.
|
||||
return '`' . strtr($replacement, array('`' => '', '.' => '')) . '`';
|
||||
return '`' . strtr($replacement, ['`' => '', '.' => '']) . '`';
|
||||
break;
|
||||
|
||||
case 'raw':
|
||||
@@ -278,7 +278,7 @@ class Database
|
||||
/**
|
||||
* Escapes and quotes a string using values passed, and executes the query.
|
||||
*/
|
||||
public function query($db_string, $db_values = array())
|
||||
public function query($db_string, $db_values = [])
|
||||
{
|
||||
// One more query....
|
||||
$this->query_count ++;
|
||||
@@ -293,10 +293,10 @@ class Database
|
||||
if (!$security_override && !empty($db_values))
|
||||
{
|
||||
// Set some values for use in the callback function.
|
||||
$this->db_callback = array($db_values, $this->connection);
|
||||
$this->db_callback = [$db_values, $this->connection];
|
||||
|
||||
// Insert the values passed to this function.
|
||||
$db_string = preg_replace_callback('~{([a-z_]+)(?::([a-zA-Z0-9_-]+))?}~', array(&$this, 'replacement_callback'), $db_string);
|
||||
$db_string = preg_replace_callback('~{([a-z_]+)(?::([a-zA-Z0-9_-]+))?}~', [&$this, 'replacement_callback'], $db_string);
|
||||
|
||||
// Save some memory.
|
||||
$this->db_callback = [];
|
||||
@@ -320,20 +320,20 @@ class Database
|
||||
* Escapes and quotes a string just like db_query, but does not execute the query.
|
||||
* Useful for debugging purposes.
|
||||
*/
|
||||
public function quote($db_string, $db_values = array())
|
||||
public function quote($db_string, $db_values = [])
|
||||
{
|
||||
// Please, just use new style queries.
|
||||
if (strpos($db_string, '\'') !== false)
|
||||
trigger_error('Hack attempt!', 'Illegal character (\') used in query.', E_USER_ERROR);
|
||||
|
||||
// Save some values for use in the callback function.
|
||||
$this->db_callback = array($db_values, $this->connection);
|
||||
$this->db_callback = [$db_values, $this->connection];
|
||||
|
||||
// Insert the values passed to this function.
|
||||
$db_string = preg_replace_callback('~{([a-z_]+)(?::([a-zA-Z0-9_-]+))?}~', array(&$this, 'replacement_callback'), $db_string);
|
||||
$db_string = preg_replace_callback('~{([a-z_]+)(?::([a-zA-Z0-9_-]+))?}~', [&$this, 'replacement_callback'], $db_string);
|
||||
|
||||
// Save some memory.
|
||||
$this->db_callback = array();
|
||||
$this->db_callback = [];
|
||||
|
||||
return $db_string;
|
||||
}
|
||||
@@ -341,12 +341,12 @@ class Database
|
||||
/**
|
||||
* Executes a query, returning an array of all the rows it returns.
|
||||
*/
|
||||
public function queryRow($db_string, $db_values = array())
|
||||
public function queryRow($db_string, $db_values = [])
|
||||
{
|
||||
$res = $this->query($db_string, $db_values);
|
||||
|
||||
if (!$res || $this->num_rows($res) == 0)
|
||||
return array();
|
||||
return [];
|
||||
|
||||
$row = $this->fetch_row($res);
|
||||
$this->free_result($res);
|
||||
@@ -357,14 +357,14 @@ class Database
|
||||
/**
|
||||
* Executes a query, returning an array of all the rows it returns.
|
||||
*/
|
||||
public function queryRows($db_string, $db_values = array())
|
||||
public function queryRows($db_string, $db_values = [])
|
||||
{
|
||||
$res = $this->query($db_string, $db_values);
|
||||
|
||||
if (!$res || $this->num_rows($res) == 0)
|
||||
return array();
|
||||
return [];
|
||||
|
||||
$rows = array();
|
||||
$rows = [];
|
||||
while ($row = $this->fetch_row($res))
|
||||
$rows[] = $row;
|
||||
|
||||
@@ -376,14 +376,14 @@ class Database
|
||||
/**
|
||||
* Executes a query, returning an array of all the rows it returns.
|
||||
*/
|
||||
public function queryPair($db_string, $db_values = array())
|
||||
public function queryPair($db_string, $db_values = [])
|
||||
{
|
||||
$res = $this->query($db_string, $db_values);
|
||||
|
||||
if (!$res || $this->num_rows($res) == 0)
|
||||
return array();
|
||||
return [];
|
||||
|
||||
$rows = array();
|
||||
$rows = [];
|
||||
while ($row = $this->fetch_row($res))
|
||||
$rows[$row[0]] = $row[1];
|
||||
|
||||
@@ -395,14 +395,14 @@ class Database
|
||||
/**
|
||||
* Executes a query, returning an array of all the rows it returns.
|
||||
*/
|
||||
public function queryPairs($db_string, $db_values = array())
|
||||
public function queryPairs($db_string, $db_values = [])
|
||||
{
|
||||
$res = $this->query($db_string, $db_values);
|
||||
|
||||
if (!$res || $this->num_rows($res) == 0)
|
||||
return array();
|
||||
return [];
|
||||
|
||||
$rows = array();
|
||||
$rows = [];
|
||||
while ($row = $this->fetch_assoc($res))
|
||||
{
|
||||
$key_value = reset($row);
|
||||
@@ -417,12 +417,12 @@ class Database
|
||||
/**
|
||||
* Executes a query, returning an associative array of all the rows it returns.
|
||||
*/
|
||||
public function queryAssoc($db_string, $db_values = array())
|
||||
public function queryAssoc($db_string, $db_values = [])
|
||||
{
|
||||
$res = $this->query($db_string, $db_values);
|
||||
|
||||
if (!$res || $this->num_rows($res) == 0)
|
||||
return array();
|
||||
return [];
|
||||
|
||||
$row = $this->fetch_assoc($res);
|
||||
$this->free_result($res);
|
||||
@@ -433,14 +433,14 @@ class Database
|
||||
/**
|
||||
* Executes a query, returning an associative array of all the rows it returns.
|
||||
*/
|
||||
public function queryAssocs($db_string, $db_values = array(), $connection = null)
|
||||
public function queryAssocs($db_string, $db_values = [], $connection = null)
|
||||
{
|
||||
$res = $this->query($db_string, $db_values);
|
||||
|
||||
if (!$res || $this->num_rows($res) == 0)
|
||||
return array();
|
||||
return [];
|
||||
|
||||
$rows = array();
|
||||
$rows = [];
|
||||
while ($row = $this->fetch_assoc($res))
|
||||
$rows[] = $row;
|
||||
|
||||
@@ -452,7 +452,7 @@ class Database
|
||||
/**
|
||||
* Executes a query, returning the first value of the first row.
|
||||
*/
|
||||
public function queryValue($db_string, $db_values = array())
|
||||
public function queryValue($db_string, $db_values = [])
|
||||
{
|
||||
$res = $this->query($db_string, $db_values);
|
||||
|
||||
@@ -469,14 +469,14 @@ class Database
|
||||
/**
|
||||
* Executes a query, returning an array of the first value of each row.
|
||||
*/
|
||||
public function queryValues($db_string, $db_values = array())
|
||||
public function queryValues($db_string, $db_values = [])
|
||||
{
|
||||
$res = $this->query($db_string, $db_values);
|
||||
|
||||
if (!$res || $this->num_rows($res) == 0)
|
||||
return array();
|
||||
return [];
|
||||
|
||||
$rows = array();
|
||||
$rows = [];
|
||||
while ($row = $this->fetch_row($res))
|
||||
$rows[] = $row[0];
|
||||
|
||||
@@ -496,7 +496,7 @@ class Database
|
||||
|
||||
// Inserting data as a single row can be done as a single array.
|
||||
if (!is_array($data[array_rand($data)]))
|
||||
$data = array($data);
|
||||
$data = [$data];
|
||||
|
||||
// Create the mold for a single row insert.
|
||||
$insertData = '(';
|
||||
@@ -514,7 +514,7 @@ class Database
|
||||
$indexed_columns = array_keys($columns);
|
||||
|
||||
// Here's where the variables are injected to the query.
|
||||
$insertRows = array();
|
||||
$insertRows = [];
|
||||
foreach ($data as $dataRow)
|
||||
$insertRows[] = $this->quote($insertData, array_combine($indexed_columns, $dataRow));
|
||||
|
||||
@@ -527,9 +527,6 @@ class Database
|
||||
VALUES
|
||||
' . implode(',
|
||||
', $insertRows),
|
||||
array(
|
||||
'security_override' => true,
|
||||
)
|
||||
);
|
||||
['security_override' => true]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user