/** @var PDO|mysqli */
protected $connection;
protected $driver;
- private $emulate_prepares = false;
+ protected $emulate_prepares = false;
private $error = false;
private $errorno = 0;
private $affected_rows = 0;
{
// Use environment variables for mysql if they are set beforehand
if (!empty($server['MYSQL_HOST'])
- && (!empty($server['MYSQL_USERNAME'] || !empty($server['MYSQL_USER'])))
+ && (!empty($server['MYSQL_USERNAME']) || !empty($server['MYSQL_USER']))
&& $server['MYSQL_PASSWORD'] !== false
&& !empty($server['MYSQL_DATABASE']))
{
}
$this->emulate_prepares = (bool)$this->configCache->get('database', 'emulate_prepares');
+ $this->pdo_emulate_prepares = (bool)$this->configCache->get('database', 'pdo_emulate_prepares');
- if (class_exists('\PDO') && in_array('mysql', PDO::getAvailableDrivers())) {
+ if (!$this->configCache->get('database', 'disable_pdo') && class_exists('\PDO') && in_array('mysql', PDO::getAvailableDrivers())) {
$this->driver = 'pdo';
$connect = "mysql:host=" . $server . ";dbname=" . $db;
try {
$this->connection = @new PDO($connect, $user, $pass);
- $this->connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
+ $this->connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, $this->pdo_emulate_prepares);
$this->connected = true;
} catch (PDOException $e) {
$this->connected = false;
}
$watchlist = explode(',', $this->configCache->get('system', 'db_log_index_watch'));
- $blacklist = explode(',', $this->configCache->get('system', 'db_log_index_blacklist'));
+ $denylist = explode(',', $this->configCache->get('system', 'db_log_index_denylist'));
while ($row = $this->fetch($r)) {
if ((intval($this->configCache->get('system', 'db_loglimit_index')) > 0)) {
$log = true;
}
- if (in_array($row['key'], $blacklist) || ($row['key'] == "")) {
+ if (in_array($row['key'], $denylist) || ($row['key'] == "")) {
$log = false;
}
$row['key'] . "\t" . $row['rows'] . "\t" . $row['Extra'] . "\t" .
basename($backtrace[1]["file"]) . "\t" .
$backtrace[1]["line"] . "\t" . $backtrace[2]["function"] . "\t" .
- substr($query, 0, 2000) . "\n", FILE_APPEND);
+ substr($query, 0, 4000) . "\n", FILE_APPEND);
}
}
}
/**
- * Removes every not whitelisted character from the identifier string
+ * Removes every not allowlisted character from the identifier string
*
* @param string $identifier
*
$this->errorno = $errorno;
}
- $this->profiler->saveTimestamp($stamp1, 'database', System::callstack());
+ $this->profiler->saveTimestamp($stamp1, 'database');
if ($this->configCache->get('system', 'db_log')) {
$stamp2 = microtime(true);
@file_put_contents($this->configCache->get('system', 'db_log'), DateTimeFormat::utcNow() . "\t" . $duration . "\t" .
basename($backtrace[1]["file"]) . "\t" .
$backtrace[1]["line"] . "\t" . $backtrace[2]["function"] . "\t" .
- substr($this->replaceParameters($sql, $args), 0, 2000) . "\n", FILE_APPEND);
+ substr($this->replaceParameters($sql, $args), 0, 4000) . "\n", FILE_APPEND);
}
}
return $retval;
$this->errorno = $errorno;
}
- $this->profiler->saveTimestamp($stamp, "database_write", System::callstack());
+ $this->profiler->saveTimestamp($stamp, "database_write");
return $retval;
}
}
}
- $this->profiler->saveTimestamp($stamp1, 'database', System::callstack());
+ $this->profiler->saveTimestamp($stamp1, 'database');
return $columns;
}
* @return boolean was the insert successful?
* @throws \Exception
*/
- public function insert($table, $param, $on_duplicate_update = false)
+ public function insert($table, array $param, bool $on_duplicate_update = false)
{
if (empty($table) || empty($param)) {
$this->logger->info('Table and fields have to be set');
$success = $this->e("LOCK TABLES " . DBA::buildTableString($table) . " WRITE");
if ($this->driver == 'pdo') {
- $this->connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
+ $this->connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, $this->pdo_emulate_prepares);
}
if (!$success) {
$success = $this->e("UNLOCK TABLES");
if ($this->driver == 'pdo') {
- $this->connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
+ $this->connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, $this->pdo_emulate_prepares);
$this->e("SET autocommit=1");
} else {
$this->connection->autocommit(true);
/**
* Select rows from a table
*
- * @param string|array $table Table name or array [schema => table]
- * @param array $fields Array of selected fields, empty for all
- * @param array $condition Array of fields for condition
- * @param array $params Array of several parameters
- *
- * @return boolean|object
*
* Example:
- * $table = "item";
- * $fields = array("id", "uri", "uid", "network");
+ * $table = 'item';
+ * or:
+ * $table = ['schema' => 'table'];
+ * @see DBA::buildTableString()
*
- * $condition = array("uid" => 1, "network" => 'dspr');
+ * $fields = ['id', 'uri', 'uid', 'network'];
+ *
+ * $condition = ['uid' => 1, 'network' => 'dspr', 'blocked' => true];
* or:
- * $condition = array("`uid` = ? AND `network` IN (?, ?)", 1, 'dfrn', 'dspr');
+ * $condition = ['`uid` = ? AND `network` IN (?, ?)', 1, 'dfrn', 'dspr'];
+ * @see DBA::buildCondition()
*
- * $params = array("order" => array("id", "received" => true), "limit" => 10);
+ * $params = ['order' => ['id', 'received' => true, 'created' => 'ASC'), 'limit' => 10];
+ * @see DBA::buildParameter()
*
* $data = DBA::select($table, $fields, $condition, $params);
+ *
+ * @param string|array $table Table name or array [schema => table]
+ * @param array $fields Array of selected fields, empty for all
+ * @param array $condition Array of fields for condition
+ * @param array $params Array of several parameters
+ * @return boolean|object
* @throws \Exception
*/
public function select($table, array $fields = [], array $condition = [], array $params = [])
break;
}
- $this->profiler->saveTimestamp($stamp1, 'database', System::callstack());
+ $this->profiler->saveTimestamp($stamp1, 'database');
return $ret;
}