2010-07-02 01:48:07 +02:00
|
|
|
<?php
|
2018-01-25 03:08:45 +01:00
|
|
|
|
2018-07-20 04:15:57 +02:00
|
|
|
use Friendica\Database\dba;
|
2010-07-02 01:48:07 +02:00
|
|
|
|
2012-04-12 15:50:11 +02:00
|
|
|
function dbesc($str) {
|
2017-10-11 14:56:36 +02:00
|
|
|
if (dba::$connected) {
|
|
|
|
return(dba::escape($str));
|
2016-10-22 12:14:41 +02:00
|
|
|
} else {
|
2012-04-12 15:50:11 +02:00
|
|
|
return(str_replace("'","\\'",$str));
|
2016-10-22 12:14:41 +02:00
|
|
|
}
|
2017-03-05 22:56:50 +01:00
|
|
|
}
|
2012-01-02 20:10:23 +01:00
|
|
|
|
2017-09-15 08:07:34 +02: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 03:05:18 +01:00
|
|
|
* @return array|bool Query array
|
2017-09-15 08:07:34 +02:00
|
|
|
*/
|
2012-04-12 15:50:11 +02:00
|
|
|
function q($sql) {
|
2017-04-24 08:24:03 +02:00
|
|
|
$args = func_get_args();
|
|
|
|
unset($args[0]);
|
2011-01-11 05:14:19 +01:00
|
|
|
|
2017-10-11 14:56:36 +02:00
|
|
|
if (!dba::$connected) {
|
2017-09-14 07:19:05 +02:00
|
|
|
return false;
|
|
|
|
}
|
2017-01-13 08:46:47 +01:00
|
|
|
|
2017-10-11 14:56:36 +02:00
|
|
|
$sql = dba::clean_query($sql);
|
|
|
|
$sql = dba::any_value_fallback($sql);
|
2017-09-14 07:19:05 +02:00
|
|
|
|
|
|
|
$stmt = @vsprintf($sql, $args);
|
|
|
|
|
|
|
|
$ret = dba::p($stmt);
|
2017-01-13 08:46:47 +01:00
|
|
|
|
2017-09-14 07:19:05 +02:00
|
|
|
if (is_bool($ret)) {
|
|
|
|
return $ret;
|
2012-04-12 15:50:11 +02:00
|
|
|
}
|
2011-01-11 05:14:19 +01:00
|
|
|
|
2017-09-14 07:19:05 +02:00
|
|
|
$columns = dba::columnCount($ret);
|
|
|
|
|
|
|
|
$data = dba::inArray($ret);
|
|
|
|
|
|
|
|
if ((count($data) == 0) && ($columns == 0)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $data;
|
2017-03-05 22:56:50 +01:00
|
|
|
}
|
2010-07-02 01:48:07 +02:00
|
|
|
|
2012-07-05 05:37:15 +02:00
|
|
|
function dba_timer() {
|
|
|
|
return microtime(true);
|
|
|
|
}
|