2010-07-01 19:48:07 -04:00
|
|
|
<?php
|
2020-02-09 10:34:23 -05:00
|
|
|
/**
|
|
|
|
* @copyright Copyright (C) 2020, Friendica
|
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
2018-01-24 21:08:45 -05:00
|
|
|
|
2018-07-20 08:19:26 -04:00
|
|
|
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
|
|
|
*
|
2018-08-23 09:51:58 -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
|
|
|
*
|
2019-01-07 10:24:06 -05:00
|
|
|
* @param $sql
|
2018-01-05 21:05:18 -05:00
|
|
|
* @return array|bool Query array
|
2019-01-07 10:24:06 -05:00
|
|
|
* @throws Exception
|
2018-07-30 22:06:22 -04:00
|
|
|
* @deprecated
|
2017-09-15 02:07:34 -04:00
|
|
|
*/
|
2012-04-12 09:50:11 -04:00
|
|
|
function q($sql) {
|
2017-04-24 02:24:03 -04:00
|
|
|
$args = func_get_args();
|
|
|
|
unset($args[0]);
|
2011-01-10 23:14:19 -05:00
|
|
|
|
2019-06-06 18:10:45 -04:00
|
|
|
if (!DBA::connected()) {
|
2017-09-14 01:19:05 -04:00
|
|
|
return false;
|
|
|
|
}
|
2017-01-13 02:46:47 -05:00
|
|
|
|
2018-07-20 21:59:17 -04:00
|
|
|
$sql = DBA::cleanQuery($sql);
|
2018-07-20 21:58:30 -04:00
|
|
|
$sql = DBA::anyValueFallback($sql);
|
2017-09-14 01:19:05 -04:00
|
|
|
|
|
|
|
$stmt = @vsprintf($sql, $args);
|
|
|
|
|
2018-07-20 08:19:26 -04:00
|
|
|
$ret = DBA::p($stmt);
|
2017-01-13 02:46:47 -05:00
|
|
|
|
2017-09-14 01:19:05 -04:00
|
|
|
if (is_bool($ret)) {
|
|
|
|
return $ret;
|
2012-04-12 09:50:11 -04:00
|
|
|
}
|
2011-01-10 23:14:19 -05:00
|
|
|
|
2018-07-20 08:19:26 -04:00
|
|
|
$columns = DBA::columnCount($ret);
|
2017-09-14 01:19:05 -04:00
|
|
|
|
2018-07-20 22:03:40 -04:00
|
|
|
$data = DBA::toArray($ret);
|
2017-09-14 01:19:05 -04:00
|
|
|
|
|
|
|
if ((count($data) == 0) && ($columns == 0)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $data;
|
2017-03-05 16:56:50 -05:00
|
|
|
}
|