friendica/include/dba.php

65 lines
1.5 KiB
PHP
Raw Permalink Normal View History

2010-07-02 01:48:07 +02:00
<?php
/**
* @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/>.
*
*/
use Friendica\Database\DBA;
2010-07-02 01:48:07 +02:00
2017-09-15 08:07:34 +02:00
/**
2020-01-19 07:05:23 +01:00
* execute SQL query with printf style args - deprecated
2017-09-15 08:07:34 +02:00
*
* Please use the DBA:: functions instead:
* DBA::select, DBA::exists, DBA::insert
* DBA::delete, DBA::update, DBA::p, DBA::e
2017-09-15 08:07:34 +02:00
*
* @param $sql
* @return array|bool Query array
* @throws Exception
* @deprecated
2017-09-15 08:07:34 +02:00
*/
function q($sql) {
2017-04-24 08:24:03 +02:00
$args = func_get_args();
unset($args[0]);
2019-06-07 00:10:45 +02: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-21 04:03:40 +02:00
$data = DBA::toArray($ret);
if ((count($data) == 0) && ($columns == 0)) {
return true;
}
return $data;
}