self::$connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
self::$connected = true;
} catch (PDOException $e) {
self::$connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
self::$connected = true;
} catch (PDOException $e) {
switch (self::$driver) {
case 'pdo':
return substr(@self::$connection->quote($str, PDO::PARAM_STR), 1, -1);
switch (self::$driver) {
case 'pdo':
return substr(@self::$connection->quote($str, PDO::PARAM_STR), 1, -1);
* @usage Example: $r = p("SELECT * FROM `item` WHERE `guid` = ?", $guid);
*
* Please only use it with complicated queries.
* @usage Example: $r = p("SELECT * FROM `item` WHERE `guid` = ?", $guid);
*
* Please only use it with complicated queries.
if ((substr_count($sql, '?') != count($args)) && (count($args) > 0)) {
// Question: Should we continue or stop the query here?
if ((substr_count($sql, '?') != count($args)) && (count($args) > 0)) {
// Question: Should we continue or stop the query here?
- logger('Parameter mismatch. Query "'.$sql.'" - Parameters '.print_r($args, true), LOGGER_DEBUG);
+ Logger::log('Parameter mismatch. Query "'.$sql.'" - Parameters '.print_r($args, true), Logger::DEBUG);
System::callstack(8)."\n".self::replaceParameters($sql, $args));
// On a lost connection we try to reconnect - but only once.
System::callstack(8)."\n".self::replaceParameters($sql, $args));
// On a lost connection we try to reconnect - but only once.
if (self::$in_retrial || !self::reconnect()) {
// It doesn't make sense to continue when the database connection was lost
if (self::$in_retrial) {
if (self::$in_retrial || !self::reconnect()) {
// It doesn't make sense to continue when the database connection was lost
if (self::$in_retrial) {
self::$in_retrial = true;
$ret = self::p($sql, $args);
self::$in_retrial = false;
self::$in_retrial = true;
$ret = self::p($sql, $args);
self::$in_retrial = false;
if ($a->getConfigValue('system', 'db_log')) {
$stamp2 = microtime(true);
if ($a->getConfigValue('system', 'db_log')) {
$stamp2 = microtime(true);
- * Please use dba::delete, dba::insert, dba::update, ... instead
+ * Please use DBA::delete, DBA::insert, DBA::update, ... instead
*
* @param string $sql SQL statement
* @return boolean Was the query successfull? False is returned only if an error occurred
*
* @param string $sql SQL statement
* @return boolean Was the query successfull? False is returned only if an error occurred
System::callstack(8)."\n".self::replaceParameters($sql, $params));
// On a lost connection we simply quit.
// A reconnect like in self::p could be dangerous with modifications
if ($errorno == 2006) {
System::callstack(8)."\n".self::replaceParameters($sql, $params));
// On a lost connection we simply quit.
// A reconnect like in self::p could be dangerous with modifications
if ($errorno == 2006) {
* @param array $param parameter array
* @param bool $on_duplicate_update Do an update on a duplicate entry
*
* @param array $param parameter array
* @param bool $on_duplicate_update Do an update on a duplicate entry
*
*/
public static function insert($table, $param, $on_duplicate_update = false) {
if (empty($table) || empty($param)) {
*/
public static function insert($table, $param, $on_duplicate_update = false) {
if (empty($table) || empty($param)) {
public static function delete($table, array $conditions, array $options = [], $in_process = false, array &$callstack = [])
{
if (empty($table) || empty($conditions)) {
public static function delete($table, array $conditions, array $options = [], $in_process = false, array &$callstack = [])
{
if (empty($table) || empty($conditions)) {
- $cascade = defaults($options, 'cascade', true);
+ // Don't use "defaults" here, since it would set "false" to "true"
+ if (isset($options['cascade'])) {
+ $cascade = $options['cascade'];
+ } else {
+ $cascade = true;
+ }
// To speed up the whole process we cache the table relations
if ($cascade && count(self::$relation) == 0) {
// To speed up the whole process we cache the table relations
if ($cascade && count(self::$relation) == 0) {
if ((count($command['conditions']) > 1) || is_int($first_key)) {
$sql = "DELETE FROM `" . $command['table'] . "`" . $condition_string;
if ((count($command['conditions']) > 1) || is_int($first_key)) {
$sql = "DELETE FROM `" . $command['table'] . "`" . $condition_string;
$sql = "DELETE FROM `" . $table . "` WHERE `" . $field . "` IN (" .
substr(str_repeat("?, ", count($field_values)), 0, -2) . ");";
$sql = "DELETE FROM `" . $table . "` WHERE `" . $field . "` IN (" .
substr(str_repeat("?, ", count($field_values)), 0, -2) . ");";
public static function update($table, $fields, $condition, $old_fields = []) {
if (empty($table) || empty($fields) || empty($condition)) {
public static function update($table, $fields, $condition, $old_fields = []) {
if (empty($table) || empty($fields) || empty($condition)) {
- * $data = dba::select($table, $fields, $condition, $params);
+ * $data = DBA::select($table, $fields, $condition, $params);
*/
public static function select($table, array $fields = [], array $condition = [], array $params = [])
{
*/
public static function select($table, array $fields = [], array $condition = [], array $params = [])
{
* or:
* $condition = ["`uid` = ? AND `network` IN (?, ?)", 1, 'dfrn', 'dspr'];
*
* or:
* $condition = ["`uid` = ? AND `network` IN (?, ?)", 1, 'dfrn', 'dspr'];
*
/* Workaround for MySQL Bug #64791.
* Never mix data types inside any IN() condition.
* In case of mixed types, cast all as string.
/* Workaround for MySQL Bug #64791.
* Never mix data types inside any IN() condition.
* In case of mixed types, cast all as string.
case 'mysqli':
// MySQLi offers both a mysqli_stmt and a mysqli_result class.
// We should be careful not to assume the object type of $stmt
case 'mysqli':
// MySQLi offers both a mysqli_stmt and a mysqli_result class.
// We should be careful not to assume the object type of $stmt