2010-07-01 23:48:07 +00:00
|
|
|
<?php
|
2018-01-25 02:08:45 +00:00
|
|
|
|
2018-07-20 12:19:26 +00:00
|
|
|
use Friendica\Database\DBA;
|
2010-07-01 23:48:07 +00:00
|
|
|
|
2012-04-12 13:50:11 +00:00
|
|
|
function dbesc($str) {
|
2018-07-20 12:19:26 +00:00
|
|
|
if (DBA::$connected) {
|
|
|
|
return(DBA::escape($str));
|
2016-10-22 10:14:41 +00:00
|
|
|
} else {
|
2012-04-12 13:50:11 +00:00
|
|
|
return(str_replace("'","\\'",$str));
|
2016-10-22 10:14:41 +00:00
|
|
|
}
|
2017-03-05 21:56:50 +00:00
|
|
|
}
|
2012-01-02 19:10:23 +00:00
|
|
|
|
2017-09-15 06:07:34 +00:00
|
|
|
/**
|
|
|
|
* @brief execute SQL query with printf style args - deprecated
|
|
|
|
*
|
|
|
|
* Please use the dba:: functions instead:
|
|
|
|
* dba::select, dba::exists, dba::insert
|
|
|
|
* dba::delete, dba::update, dba::p, dba::e
|
|
|
|
*
|
|
|
|
* @param $args Query parameters (1 to N parameters of different types)
|
2018-01-06 02:05:18 +00:00
|
|
|
* @return array|bool Query array
|
2017-09-15 06:07:34 +00:00
|
|
|
*/
|
2012-04-12 13:50:11 +00:00
|
|
|
function q($sql) {
|
2017-04-24 06:24:03 +00:00
|
|
|
$args = func_get_args();
|
|
|
|
unset($args[0]);
|
2011-01-11 04:14:19 +00:00
|
|
|
|
2018-07-20 12:19:26 +00:00
|
|
|
if (!DBA::$connected) {
|
2017-09-14 05:19:05 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-01-13 07:46:47 +00:00
|
|
|
|
2018-07-20 12:19:26 +00:00
|
|
|
$sql = DBA::clean_query($sql);
|
|
|
|
$sql = DBA::any_value_fallback($sql);
|
2017-09-14 05:19:05 +00:00
|
|
|
|
|
|
|
$stmt = @vsprintf($sql, $args);
|
|
|
|
|
2018-07-20 12:19:26 +00:00
|
|
|
$ret = DBA::p($stmt);
|
2017-01-13 07:46:47 +00:00
|
|
|
|
2017-09-14 05:19:05 +00:00
|
|
|
if (is_bool($ret)) {
|
|
|
|
return $ret;
|
2012-04-12 13:50:11 +00:00
|
|
|
}
|
2011-01-11 04:14:19 +00:00
|
|
|
|
2018-07-20 12:19:26 +00:00
|
|
|
$columns = DBA::columnCount($ret);
|
2017-09-14 05:19:05 +00:00
|
|
|
|
2018-07-20 12:19:26 +00:00
|
|
|
$data = DBA::inArray($ret);
|
2017-09-14 05:19:05 +00:00
|
|
|
|
|
|
|
if ((count($data) == 0) && ($columns == 0)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $data;
|
2017-03-05 21:56:50 +00:00
|
|
|
}
|
2010-07-01 23:48:07 +00:00
|
|
|
|
2012-07-05 03:37:15 +00:00
|
|
|
function dba_timer() {
|
|
|
|
return microtime(true);
|
|
|
|
}
|