DB_connector::new_query() returns a query result object on success. Its result_length() reports the row count, fetch() returns row arrays or null for an empty result, and result(row,column) retrieves one value.
$result = $connection->new_query($sql, false, true);
if ($result === false || $result->getError() !== false || $result->getErrorNo() != 0) {
throw new RuntimeException('Database query failed.');
}
$rows = $result->fetch() ?? [];
$value = $result->result(0, 'NAME');
if ($value === false) {
// The requested value is absent; do not confuse this with numeric/string zero.
}
$sql is a trusted owning-page query with properly validated values; this example does not authorize arbitrary SQL. The third argument requests an error-bearing result object when possible, so always check false before calling methods. getError() is false after success, including an empty SELECT. Keep database credentials in private installation configuration.