class Min_DB {
var $extension = "JSON", $server_info, $errno, $error, $_url;
- function query($path, $content = array(), $method = 'GET') {
+ /** Performs query
+ * @param string
+ * @param array
+ * @param string
+ * @return mixed
+ */
+ function rootQuery($path, $content = array(), $method = 'GET') {
@ini_set('track_errors', 1); // @ - may be disabled
- $file = @file_get_contents($this->_url . ($this->_db != "" ? "$this->_db/" : "") . $path, false, stream_context_create(array('http' => array(
+ $file = @file_get_contents($this->_url . '/' . ltrim($path, '/'), false, stream_context_create(array('http' => array(
'method' => $method,
'content' => json_encode($content),
'ignore_errors' => 1, // available since PHP 5.2.10
return $return;
}
+ /** Performs query relative to actual selected DB
+ * @param string
+ * @param array
+ * @param string
+ * @return mixed
+ */
+ function query($path, $content = array(), $method = 'GET') {
+ return $this->rootQuery(($this->_db != "" ? "$this->_db/" : "/") . ltrim($path, '/'), $content, $method);
+ }
+
function connect($server, $username, $password) {
$this->_url = "http://$username:$password@$server/";
$return = $this->query('');
function get_databases() {
global $connection;
- $return = $connection->query('_aliases');
+ $return = $connection->rootQuery('_aliases');
if ($return) {
$return = array_keys($return);
}
*/
function create_database($db) {
global $connection;
- return $connection->query(urlencode($db), array(), 'PUT');
+ return $connection->rootQuery(urlencode($db), array(), 'PUT');
}
/** Drop databases
*/
function drop_databases($databases) {
global $connection;
- return $connection->query(urlencode(implode(',', $databases)), array(), 'DELETE');
+ return $connection->rootQuery(urlencode(implode(',', $databases)), array(), 'DELETE');
}
/** Drop tables