function hasCStyleEscapes(): bool {
static $c_style;
if ($c_style === null) {
- $sql_mode = $this->conn->result("SHOW VARIABLES LIKE 'sql_mode'", 1);
+ $sql_mode = get_val("SHOW VARIABLES LIKE 'sql_mode'", 1, $this->conn);
$c_style = (strpos($sql_mode, 'NO_BACKSLASH_ESCAPES') === false);
}
return $c_style;
function hasCStyleEscapes(): bool {
static $c_style;
if ($c_style === null) {
- $c_style = ($this->conn->result("SHOW standard_conforming_strings") == "off");
+ $c_style = (get_val("SHOW standard_conforming_strings", 0, $this->conn) == "off");
}
return $c_style;
}
if (min_version(9, 0, $connection)) {
$connection->query("SET application_name = 'Adminer'");
}
- $version = $connection->result("SELECT version()");
+ $version = get_val("SELECT version()", 0, $connection);
$connection->flavor = (preg_match('~CockroachDB~', $version) ? 'cockroach' : '');
$connection->server_info = preg_replace('~^\D*([\d.]+[-\w]*).*~', '\1', $version);
if ($connection->flavor == 'cockroach') { // we don't use "PostgreSQL / CockroachDB" by default because it's too long
$connection2 = $connection;
}
$return = array();
- $table_oid = $connection2->result("SELECT oid FROM pg_class WHERE relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = current_schema()) AND relname = " . q($table));
+ $table_oid = get_val("SELECT oid FROM pg_class WHERE relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = current_schema()) AND relname = " . q($table), 0, $connection2);
$columns = get_key_vals("SELECT attnum, attname FROM pg_attribute WHERE attrelid = $table_oid AND attnum > 0", $connection2);
foreach (
get_rows("SELECT relname, indisunique::int, indisprimary::int, indkey, indoption, (indpred IS NOT NULL)::int as indispartial
}
function checkConstraints(string $table): array {
- preg_match_all('~ CHECK *(\( *(((?>[^()]*[^() ])|(?1))*) *\))~', $this->conn->result("SELECT sql FROM sqlite_master WHERE type = 'table' AND name = " . q($table)), $matches); //! could be inside a comment
+ preg_match_all('~ CHECK *(\( *(((?>[^()]*[^() ])|(?1))*) *\))~', get_val("SELECT sql FROM sqlite_master WHERE type = 'table' AND name = " . q($table), 0, $this->conn), $matches); //! could be inside a comment
return array_combine($matches[2], $matches[2]);
}
}
$connection2 = $connection;
}
$return = array();
- $sql = $connection2->result("SELECT sql FROM sqlite_master WHERE type = 'table' AND name = " . q($table));
+ $sql = get_val("SELECT sql FROM sqlite_master WHERE type = 'table' AND name = " . q($table), 0, $connection2);
if (preg_match('~\bPRIMARY\s+KEY\s*\((([^)"]+|"[^"]*"|`[^`]*`)++)~i', $sql, $match)) {
$return[""] = array("type" => "PRIMARY", "columns" => array(), "lengths" => array(), "descs" => array());
preg_match_all('~((("[^"]*+")+|(?:`[^`]*+`)+)|(\S+))(\s+(ASC|DESC))?(,\s*|$)~i', $match[1], $matches, PREG_SET_ORDER);
function next_result(): bool {
return false;
}
-
- /** Get single field from result
- * @return string|bool
- */
- function result(string $query, int $field = 0) {
- $result = $this->query($query);
- if (!is_object($result)) {
- return false;
- }
- $row = $result->fetch_row();
- return ($row ? $row[$field] : false);
- }
}
}
/** Get single value from database
-* @return string or false if error
+* @return string|false false if error
*/
-function get_val(string $query, int $field = 0): string {
+function get_val(string $query, int $field = 0, ?Db $conn = null) {
global $connection;
- return $connection->result($query, $field);
+ $conn = $conn ?: $connection;
+ $result = $conn->query($query);
+ if (!is_object($result)) {
+ return false;
+ }
+ $row = $result->fetch_row();
+ return ($row ? $row[$field] : false);
}
/** Get list of values from database
if (!$slow_query && support("kill")) {
$connection2 = connect($adminer->credentials());
if (is_object($connection2) && ($db == "" || $connection2->select_db($db))) {
- $kill = $connection2->result(connection_id()); // MySQL and MySQLi can use thread_id but it's not in PDO_MySQL
+ $kill = get_val(connection_id(), 0, $connection2); // MySQL and MySQLi can use thread_id but it's not in PDO_MySQL
echo script("const timeout = setTimeout(() => { ajax('" . js_escape(ME) . "script=kill', function () {}, 'kill=$kill&token=$token'); }, 1000 * $timeout);");
}
}