public function select($table, $row, $column = null, $filter = "")
 {
     $tscan_params = array();
     if (!empty($filter)) {
         MMB::debug(" filter = {$filter} ## <br>");
         $tscan_params["filterString"] = $filter;
     }
     $scan = new \TScan($tscan_params);
     $scanner = $this->_hbaseclient->scannerOpenWithScan("{$table}", $scan);
     $res = array();
     $idx = 0;
     while ($row = $this->_hbaseclient->scannerGet($scanner)) {
         $row = $row[0];
         $res[$idx]["rowkey"] = $row->row;
         foreach ($row->columns as $qualifier => $cell) {
             $column_name = preg_replace("/^[\\w]+:/", "", $qualifier);
             $res[$idx][$column_name] = $cell->value;
         }
         $idx++;
     }
     return $res;
 }
$uri_param_query_post = isset($_GET["query_post"]) ? $_GET["query_post"] : null;
$colnames_post = isset($_POST["colname"]) ? $_POST["colname"] : null;
$tablenames_post = isset($_POST["tablename"]) ? $_POST["tablename"] : null;
$act = isset($_GET["act"]) ? $_GET["act"] : null;
if (!empty($act) && $act == "submit") {
    echo ";;;;;;;;;;;;;;;;;;;";
    print_r($colnames_post);
    print_r($tablenames_post);
    // put 'tbl1', 'row1', 'cf1:column1', 'v1'
    $cmd = "create '{$tablenames_post}', 'mysql'\n";
    foreach ($colnames_post as $col) {
        $cmd .= "put '{$tablenames_post}', 'row1', 'mysql:{$col}', ''";
    }
    //file_put_contents("tmp/create-table.txt", $cmd);
    //exec("hbase shell < tmp/create-table.txt");
    MMB::createTable($tablenames_post, "mysql");
    $cols = implode(",", $colnames_post);
    $sql = "INSERT INTO {$tablenames_post} ({$cols}) VALUES ({$cols})";
    mysql_query($sql);
}
?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>HBaseMyAdmin</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

    <!-- Le styles -->
Example #3
0
 protected static function processSelectStatement($parsed = array())
 {
     $query = $parsed["SQL"];
     // SELECT <select list> FROM <table reference>
     preg_match_all("/SELECT ([\\w,\\*`\\s]+) FROM\\s+([\\w,`]+)/i", $query, $matches);
     if (!empty($matches[1][0]) && !empty($matches[2][0])) {
         $column = $matches[1][0] == "*" ? null : $matches[1][0];
         $column = str_replace("`", "", $column);
         $column = str_replace(" ", "", $column);
         $table = str_replace("`", "", $matches[2][0]);
         $rowkey = "*";
         $filter = "";
         // SQL 有挑選特定欄位就加入 MultipleColumnPrefixFilter
         if ($column != "*" && !empty($column)) {
             // Convert Col1,Col2 => 'Col1','Col2'
             $column = "'" . str_replace(",", "','", $column) . "'";
             $filter .= "MultipleColumnPrefixFilter ({$column}) AND ";
         }
     }
     // SELECT <select list> FROM <table reference> WHERE <search condition>
     preg_match_all("/SELECT ([\\w,\\*`\\s]+) FROM\\s+([\\w,`]+)\\s+(WHERE ([\\w\\W,`\\s<=>'\"\\-:]+)*)/i", $query, $matches);
     if (!empty($matches[3])) {
         self::debug(print_r($matches, true));
         $condition_str = trim($matches[4][0]);
         //debugdump($condition_str);
         Predicate::parseMultiPredicate($condition_str);
         $predicates = Predicate::getPredicates();
         $operators = Predicate::getOperators();
         foreach ($predicates as $predicate_str) {
             $predicate = Predicate::getMappingPredicate($predicate_str);
             //new \Predicate($condition_str);
             if (!$predicate) {
                 throw new SQLBridgeException('查詢子句語意不明! (WHERE clause is ambiguity.)');
             }
             $args = $predicate->toFilterArguments();
             $qualifier = $args->qualifier;
             $op = $args->compareOperator;
             $comparator = $args->comparatorType;
             $value = $args->comparatorValue;
             $comparator = !empty($comparator) ? $comparator : $default_comparator;
             $cf = self::$hbase->getFirstColumnFamilyName($table);
             if (!preg_match("/^rowkey|id\$/i", $qualifier)) {
                 // SQL WHERE 條件子句以 SingleColumnValueFilter 處理
                 $filter .= "SingleColumnValueFilter ('{$cf}', '{$qualifier}', {$op}, '{$comparator}:{$value}', true, false)";
             } else {
                 $filter .= "RowFilter ({$op}, '{$comparator}:{$value}')";
             }
             $filter .= " " . current($operators) . " ";
             next($operators);
         }
     }
     // LIMIT
     preg_match_all("/LIMIT\\s*([\\d]+)/i", $query, $matches);
     if (!empty($matches[1][0])) {
         $limit = $matches[1][0];
         if (!empty($filter)) {
             $filter .= " AND ";
         }
         $filter .= "PageFilter ({$limit})";
     }
     if (preg_match("/^\\s*SELECT /i", $query)) {
         return MMB::select($table, $rowkey, $column, $filter);
     }
 }
 function fetch($fetch_style = \PDO::FETCH_BOTH, $cursor_orientation = \PDO::FETCH_ORI_NEXT, $cursor_offset = 0)
 {
     return MMB::fetchArray($this->_query_result, MYSQL_BOTH);
 }
$try_it_tbl = $hbase_tables[rand(0, count($hbase_tables) - 1)][0];
$uri_param_table = isset($_GET["table"]) ? $_GET["table"] : null;
$uri_param_func = isset($_GET["func"]) ? $_GET["func"] : null;
$uri_param_query_post = isset($_GET["query_post"]) ? $_GET["query_post"] : null;
$sql_query = isset($_POST["sql_query"]) ? $_POST["sql_query"] : null;
if (!empty($sql_query) && $uri_param_query_post == "submit") {
    try {
        if (preg_match("/\\s*SELECT/i", $sql_query) && !preg_match("/\\s+LIMIT\\s*([\\d]+)/i", $sql_query)) {
            $sql_query .= " LIMIT 500";
        }
        $time_start = microtime(true);
        $rs = mysql_query($sql_query);
        $time_end = microtime(true);
        $query_took_time = $time_end - $time_start;
        $user_sql_query_results = fetch_all($rs);
        $user_sql_query_filter = MMB::getLastFilter();
    } catch (Exception $e) {
        $sql_error = $e->getMessage();
    }
}
?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>HBaseMyAdmin</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

    <!-- Le styles -->
          <div class="nav-collapse">
            <ul class="nav">
              <li class="active"><a href="#">Home</a></li>
              <li><a href="#about">About</a></li>
              <li><a href="#contact">Contact</a></li>
            </ul>
          </div><!--/.nav-collapse -->
        </div>
      </div>
    </div>

    <div class="container">
<pre class="prettyprint linenums">
<?php 
if (class_exists('MMB')) {
    $debugprint = MMB::getDebugMessages();
    isset($debugprint) ? print_r($debugprint) : "";
}
/*
usort($students, function ($a, $b){
      if ($a == $b) {
          return 0;
      }
      return ($a["date_close"] > $b["date_close"]) ? -1 : 1;
});*/
?>
</pre>

      <h1>Sample PHP Application</h1>
      <p>Just a demo php application.</p>
Example #7
0
function mysql_connect22($server = "localhost", $username = NULL, $password = NULL, $new_link = false, $client_flags = 0)
{
    return MMB::connect($server, $username, $password, $new_link, $client_flags);
    //return \mysql_connect($server, $username, $password, $new_link, $client_flags);
}