friendica/include/dba.php

46 lines
748 B
PHP
Raw Normal View History

2010-07-01 19:48:07 -04:00
<?php
use Friendica\Database\DBA;
2010-07-01 19:48:07 -04:00
2017-09-15 02:07:34 -04:00
/**
2020-01-19 01:05:23 -05:00
* execute SQL query with printf style args - deprecated
2017-09-15 02:07:34 -04:00
*
* Please use the DBA:: functions instead:
* DBA::select, DBA::exists, DBA::insert
* DBA::delete, DBA::update, DBA::p, DBA::e
2017-09-15 02:07:34 -04:00
*
* @param $sql
* @return array|bool Query array
* @throws Exception
* @deprecated
2017-09-15 02:07:34 -04:00
*/
function q($sql) {
2017-04-24 02:24:03 -04:00
$args = func_get_args();
unset($args[0]);
2019-06-06 18:10:45 -04:00
if (!DBA::connected()) {
return false;
}
$sql = DBA::cleanQuery($sql);
$sql = DBA::anyValueFallback($sql);
$stmt = @vsprintf($sql, $args);
$ret = DBA::p($stmt);
if (is_bool($ret)) {
return $ret;
}
$columns = DBA::columnCount($ret);
2018-07-20 22:03:40 -04:00
$data = DBA::toArray($ret);
if ((count($data) == 0) && ($columns == 0)) {
return true;
}
return $data;
}