adminerevo/adminer/include/driver.inc.php

189 lines
4.6 KiB
PHP
Raw Normal View History

<?php
$drivers = array();
/** Add a driver
* @param string
* @param string
* @return null
*/
function add_driver($id, $name) {
global $drivers;
$drivers[$id] = $name;
}
/** Get driver name
* @param string
* @return string
*/
function get_driver($id) {
global $drivers;
return $drivers[$id];
}
/*abstract*/ class Min_SQL {
var $_conn;
2023-05-21 13:03:36 +00:00
/** Create object for performing database operations
* @param Min_DB
*/
2015-08-15 15:04:21 +00:00
function __construct($connection) {
$this->_conn = $connection;
}
2023-05-21 13:03:36 +00:00
2013-07-10 00:38:13 +00:00
/** Select data from table
* @param string
* @param array result of $adminer->selectColumnsProcess()[0]
* @param array result of $adminer->selectSearchProcess()
* @param array result of $adminer->selectColumnsProcess()[1]
* @param array result of $adminer->selectOrderProcess()
* @param int result of $adminer->selectLimitProcess()
* @param int index of page starting at zero
2014-01-09 07:14:37 +00:00
* @param bool whether to print the query
2013-07-10 00:38:13 +00:00
* @return Min_Result
*/
2014-01-15 16:23:26 +00:00
function select($table, $select, $where, $group, $order = array(), $limit = 1, $page = 0, $print = false) {
2013-07-10 00:38:13 +00:00
global $adminer, $jush;
$is_group = (count($group) < count($select));
$query = $adminer->selectQueryBuild($select, $where, $group, $order, $limit, $page);
if (!$query) {
$query = "SELECT" . limit(
($_GET["page"] != "last" && $limit != "" && $group && $is_group && $jush == "sql" ? "SQL_CALC_FOUND_ROWS " : "") . implode(", ", $select) . "\nFROM " . table($table),
2013-07-10 00:38:13 +00:00
($where ? "\nWHERE " . implode(" AND ", $where) : "") . ($group && $is_group ? "\nGROUP BY " . implode(", ", $group) : "") . ($order ? "\nORDER BY " . implode(", ", $order) : ""),
($limit != "" ? +$limit : null),
($page ? $limit * $page : 0),
"\n"
);
}
2014-02-24 02:34:00 +00:00
$start = microtime(true);
$return = $this->_conn->query($query);
2014-01-09 07:14:37 +00:00
if ($print) {
echo $adminer->selectQuery($query, $start, !$return);
2014-01-09 07:14:37 +00:00
}
2014-02-24 02:34:00 +00:00
return $return;
2013-07-10 00:38:13 +00:00
}
2023-05-21 13:03:36 +00:00
/** Delete data from table
* @param string
* @param string " WHERE ..."
* @param int 0 or 1
* @return bool
*/
function delete($table, $queryWhere, $limit = 0) {
$query = "FROM " . table($table);
return queries("DELETE" . ($limit ? limit1($table, $query, $queryWhere) : " $query$queryWhere"));
}
2023-05-21 13:03:36 +00:00
2013-07-05 22:32:15 +00:00
/** Update data in table
* @param string
2013-07-06 17:31:21 +00:00
* @param array escaped columns in keys, quoted data in values
2013-07-05 22:32:15 +00:00
* @param string " WHERE ..."
* @param int 0 or 1
2013-07-06 17:31:21 +00:00
* @param string
2013-07-05 22:32:15 +00:00
* @return bool
*/
2013-07-06 17:31:21 +00:00
function update($table, $set, $queryWhere, $limit = 0, $separator = "\n") {
$values = array();
foreach ($set as $key => $val) {
$values[] = "$key = $val";
}
$query = table($table) . " SET$separator" . implode(",$separator", $values);
2018-02-01 17:53:53 +00:00
return queries("UPDATE" . ($limit ? limit1($table, $query, $queryWhere, $separator) : " $query$queryWhere"));
2013-07-05 22:32:15 +00:00
}
2023-05-21 13:03:36 +00:00
/** Insert data into table
* @param string
2013-07-06 17:31:21 +00:00
* @param array escaped columns in keys, quoted data in values
* @return bool
*/
function insert($table, $set) {
2013-07-06 17:31:21 +00:00
return queries("INSERT INTO " . table($table) . ($set
? " (" . implode(", ", array_keys($set)) . ")\nVALUES (" . implode(", ", $set) . ")"
2013-08-08 21:50:43 +00:00
: " DEFAULT VALUES"
2013-07-06 17:31:21 +00:00
));
}
2023-05-21 13:03:36 +00:00
/** Insert or update data in table
* @param string
* @param array
2013-07-09 18:34:12 +00:00
* @param array of arrays with escaped columns in keys and quoted data in values
* @return bool
*/
2013-07-09 18:34:12 +00:00
/*abstract*/ function insertUpdate($table, $rows, $primary) {
return false;
}
2023-05-21 13:03:36 +00:00
2013-07-09 18:43:01 +00:00
/** Begin transaction
* @return bool
*/
function begin() {
return queries("BEGIN");
}
2023-05-21 13:03:36 +00:00
2018-01-31 16:28:12 +00:00
/** Commit transaction
* @return bool
*/
2013-07-09 18:43:01 +00:00
function commit() {
return queries("COMMIT");
}
2023-05-21 13:03:36 +00:00
2018-01-31 16:28:12 +00:00
/** Rollback transaction
* @return bool
*/
2013-07-09 18:43:01 +00:00
function rollback() {
return queries("ROLLBACK");
}
2023-05-21 13:03:36 +00:00
2018-03-09 17:06:19 +00:00
/** Return query with a timeout
* @param string
* @param int seconds
* @return string or null if the driver doesn't support query timeouts
*/
function slowQuery($query, $timeout) {
}
2023-05-21 13:03:36 +00:00
/** Convert column to be searchable
* @param string escaped column name
* @param array array("op" => , "val" => )
* @param array
* @return string
*/
function convertSearch($idf, $val, $field) {
return $idf;
}
2018-02-06 15:05:39 +00:00
/** Convert value returned by database to actual value
* @param string
* @param array
* @return string
*/
function value($val, $field) {
2018-02-20 21:31:49 +00:00
return (method_exists($this->_conn, 'value')
? $this->_conn->value($val, $field)
: (is_resource($val) ? stream_get_contents($val) : $val)
);
2018-02-06 15:05:39 +00:00
}
/** Quote binary string
* @param string
* @return string
*/
function quoteBinary($s) {
return q($s);
}
2023-05-21 13:03:36 +00:00
2018-01-31 16:28:12 +00:00
/** Get warnings about the last command
2018-02-01 10:43:44 +00:00
* @return string HTML
2018-01-31 16:28:12 +00:00
*/
function warnings() {
2018-02-01 10:43:44 +00:00
return '';
2018-01-31 16:28:12 +00:00
}
2023-05-21 13:03:36 +00:00
2018-02-08 10:21:33 +00:00
/** Get help link for table
* @param string
* @return string relative URL or null
*/
function tableHelp($name) {
}
2023-05-21 13:03:36 +00:00
}