SelectRows() public method

Gets rows in a table based on a WHERE filter
public SelectRows ( string $tableName, array $whereArray = null, array/string $columns = null, array/string $sortColumns = null, boolean $sortAscending = true, integer/string $limit = null ) : boolean
$tableName string The name of the table
$whereArray array (Optional) An associative array containing the column names as keys and values as data. The values must be SQL ready (i.e. quotes around strings, formatted dates, ect)
$columns array/string
$sortColumns array/string
$sortAscending boolean (Optional) TRUE for ascending; FALSE for descending This only works if $sortColumns are specified
$limit integer/string
return boolean Returns records on success or FALSE on error
Esempio n. 1
11
/** Lấy đường dẫn nhóm media */
function get_media_group_part($id = 0, $i = 1, $deepest = FALSE)
{
    $hmdb = new MySQL(true, DB_NAME, DB_HOST, DB_USER, DB_PASSWORD, DB_CHARSET);
    if (!is_numeric($id)) {
        $tableName = DB_PREFIX . 'media_groups';
        $whereArray = array('folder' => MySQL::SQLValue($id));
        $hmdb->SelectRows($tableName, $whereArray);
        $row = $hmdb->Row();
        $id = $row->id;
    }
    $bre = array();
    $sub_bre = FALSE;
    if ($deepest == FALSE) {
        $deepest = $id;
    }
    $tableName = DB_PREFIX . 'media_groups';
    $whereArray = array('id' => MySQL::SQLValue($id));
    $hmdb->SelectRows($tableName, $whereArray);
    $row = $hmdb->Row();
    $num_rows = $hmdb->RowCount();
    if ($num_rows != 0) {
        $this_id = $row->id;
        $folder = $row->folder;
        $parent = $row->parent;
        $bre['level_' . $i] = $folder;
        if ($parent != '0') {
            $inew = $i + 1;
            $sub_bre = get_media_group_part($parent, $inew, $deepest);
        }
    }
    if (is_array($sub_bre)) {
        $bre = array_merge($bre, $sub_bre);
    }
    krsort($bre);
    $part = implode("/", $bre);
    if ($deepest == $id) {
        return $part;
    } else {
        return $bre;
    }
}
/** Đăng nhập admin cp */
function admin_cp_login()
{
    global $hmuser;
    $hmdb = new MySQL(true, DB_NAME, DB_HOST, DB_USER, DB_PASSWORD, DB_CHARSET);
    hook_action('admin_cp_login');
    $user_login = hm_post('login');
    $password = hm_post('password');
    $logmein = hm_post('log-me-in');
    if (is_numeric($logmein)) {
        $tableName = DB_PREFIX . "users";
        $whereArray = array('user_login' => MySQL::SQLValue($user_login));
        $hmdb->SelectRows($tableName, $whereArray);
        if ($hmdb->HasRecords()) {
            $row = $hmdb->Row();
            $salt = $row->salt;
            $user_pass = $row->user_pass;
            $password_encode = hm_encode_str(md5($password . $salt));
            if ($password_encode == $user_pass) {
                $time = time();
                $ip = hm_ip();
                $cookie_array = array('time' => $time, 'ip' => $ip, 'user_login' => $user_login, 'admincp' => 'yes');
                $cookie_user = hm_encode_str($cookie_array);
                setcookie('admin_login', $cookie_user, time() + COOKIE_EXPIRES, '/');
                $_SESSION['admin_login'] = $cookie_user;
                return json_encode(array('status' => 'success', 'mes' => _('Đăng nhập thành công')));
            } else {
                return json_encode(array('status' => 'error', 'mes' => _('Sai mật khẩu')));
            }
        } else {
            return json_encode(array('status' => 'error', 'mes' => _('Không có tài khoản này')));
        }
    }
}
Esempio n. 3
0
        return FALSE;
    }
}
function get_uri_data($args)
{
    $hmdb = new MySQL(true, DB_NAME, DB_HOST, DB_USER, DB_PASSWORD, DB_CHARSET);
    if (!is_array($args)) {
        parse_str($args, $args);
    }
    if (isset($args['uri'])) {
        $uri = $args['uri'];
    } else {
        $uri = FALSE;
    }
    if (isset($args['id'])) {
        $id_uri = $args['id'];
    } else {
        $id_uri = FALSE;
    }
    $tableName = DB_PREFIX . "request_uri";
    if (is_numeric($id_uri)) {
        $whereArray = array('id' => MySQL::SQLValue($id_uri));
    } else {
        $whereArray = array('uri' => MySQL::SQLValue($uri));
    }
    $hmdb->SelectRows($tableName, $whereArray);
    if ($hmdb->HasRecords()) {
        $row = $hmdb->Row();
        return $row;
    } else {
Esempio n. 4
0
 /**
  * checks if a given db row based on the $idColumn & $id exists
  * @param string $table
  * @param array $filter
  * @return bool
  */
 protected function rowExists($table, array $filter)
 {
     $select = $this->conn->SelectRows($table, $filter);
     if (!$select) {
         $this->logLastError('rowExists');
         return false;
     }
     return (bool) $this->conn->RowArray(0, MYSQLI_ASSOC);
 }
function list_plugin($active = 1)
{
    $hmdb = new MySQL(true, DB_NAME, DB_HOST, DB_USER, DB_PASSWORD, DB_CHARSET);
    $tableName = DB_PREFIX . "plugin";
    $whereArray = array('active' => MySQL::SQLValue($active, MySQL::SQLVALUE_NUMBER));
    $hmdb->SelectRows($tableName, $whereArray);
    if ($hmdb->HasRecords()) {
        while ($row = $hmdb->Row()) {
            $return[] = $row->key;
        }
        return json_encode($return);
    } else {
        return array();
    }
}
function is_theme_active($theme)
{
    $hmdb = new MySQL(true, DB_NAME, DB_HOST, DB_USER, DB_PASSWORD, DB_CHARSET);
    if (is_dir(BASEPATH . HM_THEME_DIR . '/' . $theme) and is_file(BASEPATH . HM_THEME_DIR . '/' . $theme . '/init.php')) {
        $tableName = DB_PREFIX . "option";
        $whereArray = array('section' => MySQL::SQLValue('system_setting'), 'key' => MySQL::SQLValue('theme'), 'value' => MySQL::SQLValue($theme));
        $hmdb->SelectRows($tableName, $whereArray);
        if ($hmdb->HasRecords()) {
            return TRUE;
        } else {
            return FALSE;
        }
    } else {
        return FALSE;
    }
}
    $array = array('id' => $id, 'status' => TRUE);
    return json_encode($array);
}
function menu_select_choise($args = array())
{
    if (!is_array($args)) {
        parse_str($args, $args);
    }
    hook_action('menu_select_choise');
    if (isset($args['checked'])) {
        $checked = $args['checked'];
    } else {
        $checked = 0;
    }
    if (isset($args['name'])) {
        $name = $args['name'];
    } else {
        $name = 'menu';
    }
    $hmdb = new MySQL(true, DB_NAME, DB_HOST, DB_USER, DB_PASSWORD, DB_CHARSET);
    $tableName = DB_PREFIX . "object";
    $whereArray = array('key' => MySQL::SQLValue('menu'));
    $hmdb->SelectRows($tableName, $whereArray);
    $rowCount = $hmdb->RowCount();
    if (is_numeric($rowCount)) {
        $options[] = array('value' => '0', 'label' => 'Chọn một trình đơn');
        while ($row = $hmdb->Row()) {
            $options[] = array('value' => $row->id, 'label' => $row->name);
        }
        $field_array['input_type'] = 'select';
        $field_array['name'] = $name;
        $field_array['input_option'] = $options;
        $field_array['default_value'] = $checked;
        $field_array['addClass'] = 'choise_menu';
Esempio n. 8
0
<?php

include "Mysql.php";
echo "<hr>";
try {
    $filter["ALUNO_NOME"] = MySQL::SQLValue('%');
    $db = new MySQL();
    if (!$db) {
        echo " bd não instanciado! <br><br>";
    } else {
        echo " bd instanciado.<br><br>";
    }
    $db->SelectRows("ALUNO");
    if ($db->RowCount() > 0) {
        echo "Conectado.<br><br><hr>";
    }
    echo "<br>Tabela: aluno <p>";
    echo $db->GetHTML();
    echo '<br><br>';
    $db->Close();
} catch (Exception $e) {
    echo "Erro: ", $e->getMessage(), "\n";
}
echo "<hr>";
try {
    //$filter["ALUNO_NOME"] = MySQL::SQLValue('%');
    //exibir tabela MATERIA
    echo "Tabela: materia <p>";
    $db->SelectRows("MATERIA");
    echo $db->GetHTML();
    echo '<br><br>';
function admin_cp_newpw()
{
    global $hmuser;
    $hmdb = new MySQL(true, DB_NAME, DB_HOST, DB_USER, DB_PASSWORD, DB_CHARSET);
    hook_action('newpw_checkkey');
    $key = hm_post('key');
    $password = hm_post('password');
    $password2 = hm_post('password2');
    if ($password == $password2) {
        $tableName = DB_PREFIX . "field";
        $whereArray = array('name' => MySQL::SQLValue('lostpw_key'), 'object_type' => MySQL::SQLValue('user'), 'val' => MySQL::SQLValue($key));
        $hmdb->SelectRows($tableName, $whereArray);
        $row = $hmdb->Row();
        $user_id = $row->object_id;
        $salt = rand(100000, 999999);
        $password_encode = hm_encode_str(md5($password . $salt));
        $tableName = DB_PREFIX . "users";
        $updateArray = array('user_pass' => MySQL::SQLValue($password_encode), 'salt' => MySQL::SQLValue($salt));
        $whereArray = array('id' => MySQL::SQLValue($user_id, MySQL::SQLVALUE_NUMBER));
        $hmdb->UpdateRows($tableName, $updateArray, $whereArray);
        return json_encode(array('status' => 'success', 'mes' => _('Đã đổi mật khẩu thành công')));
    } else {
        return json_encode(array('status' => 'error', 'mes' => _('Hai mật khẩu bạn nhập vào không khớp')));
    }
}
/** Load template user box */
function ajax_add_user($args = array())
{
    global $hmuser;
    $hmdb = new MySQL(true, DB_NAME, DB_HOST, DB_USER, DB_PASSWORD, DB_CHARSET);
    hook_action('ajax_add_user');
    if (isset($args['id_update'])) {
        $id_update = $args['id_update'];
    } else {
        $id_update = NULL;
    }
    $user_login = hm_post('user_login');
    $password = hm_post('password');
    $password2 = hm_post('password2');
    $nicename = hm_post('nicename');
    $user_email = hm_post('user_email');
    $userrole = hm_post('userrole');
    $user_group = hm_post('user_group', 0);
    $salt = rand(100000, 999999);
    $user_activation_key = '0';
    if ($password != $password2) {
        return json_encode(array('status' => 'error', 'mes' => _('Hai mật khẩu nhập vào không khớp')));
        hm_exit();
    }
    $tableName = DB_PREFIX . "users";
    /** check trùng user login */
    if (!is_numeric($id_update)) {
        $whereArray = array('user_login' => MySQL::SQLValue($user_login));
        $hmdb->SelectRows($tableName, $whereArray);
        if ($hmdb->HasRecords()) {
            return json_encode(array('status' => 'error', 'mes' => _('Tài khoản này đã tồn tại')));
            hm_exit();
        }
    }
    $password_encode = hm_encode_str(md5($password . $salt));
    /** Thêm tài khoản */
    $values["user_login"] = MySQL::SQLValue($user_login);
    $values["user_nicename"] = MySQL::SQLValue($nicename);
    $values["user_email"] = MySQL::SQLValue($user_email);
    $values["user_activation_key"] = MySQL::SQLValue($user_activation_key);
    $values["user_role"] = MySQL::SQLValue($userrole);
    $values["user_group"] = MySQL::SQLValue($user_group);
    if (is_numeric($id_update)) {
        if ($password != '') {
            $values["user_pass"] = MySQL::SQLValue($password_encode);
            $values["salt"] = MySQL::SQLValue($salt);
        }
        $whereArray = array('id' => $id_update);
        $hmdb->AutoInsertUpdate($tableName, $values, $whereArray);
        $insert_id = $id_update;
    } else {
        $values["user_pass"] = MySQL::SQLValue($password_encode);
        $values["salt"] = MySQL::SQLValue($salt);
        $insert_id = $hmdb->InsertRow($tableName, $values);
    }
    /** Lưu user field */
    foreach ($_POST as $post_key => $post_val) {
        if (is_numeric($insert_id)) {
            if (is_array($post_val)) {
                $post_val = json_encode($post_val);
            }
            $tableName = DB_PREFIX . 'field';
            if ($post_key != 'password' and $post_key != 'password2') {
                $values["name"] = MySQL::SQLValue($post_key);
                $values["val"] = MySQL::SQLValue($post_val);
                $values["object_id"] = MySQL::SQLValue($insert_id, MySQL::SQLVALUE_NUMBER);
                $values["object_type"] = MySQL::SQLValue('user');
                if (is_numeric($id_update)) {
                    $whereArray = array('object_id' => MySQL::SQLValue($id_update, MySQL::SQLVALUE_NUMBER), 'object_type' => MySQL::SQLValue('user'), 'name' => MySQL::SQLValue($post_key));
                    $hmdb->AutoInsertUpdate($tableName, $values, $whereArray);
                } else {
                    $hmdb->InsertRow($tableName, $values);
                }
            }
            unset($values);
        }
    }
    if (is_numeric($id_update)) {
        return json_encode(array('status' => 'updated', 'mes' => _('Đã sửa thông tin tài khoản : ' . $user_login)));
    } else {
        return json_encode(array('status' => 'success', 'mes' => _('Đã thêm tài khoản : ' . $user_login)));
    }
}
function content_delete_permanently($id)
{
    $hmdb = new MySQL(true, DB_NAME, DB_HOST, DB_USER, DB_PASSWORD, DB_CHARSET);
    hook_action('content_delete_permanently');
    if (is_numeric($id)) {
        /* xóa bảng content */
        $tableName = DB_PREFIX . "content";
        $whereArray = array('id' => MySQL::SQLValue($id));
        $hmdb->DeleteRows($tableName, $whereArray);
        /** Tìm các sub content */
        $whereArray = array('parent' => MySQL::SQLValue($id));
        $hmdb->SelectRows($tableName, $whereArray);
        $ids = array();
        while ($row = $hmdb->Row()) {
            $ids[] = $row->id;
        }
        foreach ($ids as $delete_id) {
            /** xóa các sub content */
            $tableName = DB_PREFIX . "content";
            $whereArray = array('id' => MySQL::SQLValue($delete_id));
            $hmdb->DeleteRows($tableName, $whereArray);
            /** xóa các sub content field */
            $tableName = DB_PREFIX . "field";
            $whereArray = array('object_id' => MySQL::SQLValue($delete_id), 'object_type' => MySQL::SQLValue('content'));
            $hmdb->DeleteRows($tableName, $whereArray);
            /* xóa các relationship */
            $tableName = DB_PREFIX . "relationship";
            $whereArray = array('object_id' => MySQL::SQLValue($delete_id));
            $hmdb->DeleteRows($tableName, $whereArray);
            /** xóa các sub request */
            $tableName = DB_PREFIX . "request_uri";
            $whereArray = array('object_id' => MySQL::SQLValue($delete_id));
            $hmdb->DeleteRows($tableName, $whereArray);
        }
        /* xóa bảng field */
        $tableName = DB_PREFIX . "field";
        $whereArray = array('object_id' => MySQL::SQLValue($id), 'object_type' => MySQL::SQLValue('content'));
        $hmdb->DeleteRows($tableName, $whereArray);
        /* xóa bảng relationship */
        $tableName = DB_PREFIX . "relationship";
        $whereArray = array('object_id' => MySQL::SQLValue($id));
        $hmdb->DeleteRows($tableName, $whereArray);
        /* xóa bảng request uri */
        $tableName = DB_PREFIX . "request_uri";
        $whereArray = array('object_id' => MySQL::SQLValue($id), 'object_type' => MySQL::SQLValue('content'));
        $hmdb->DeleteRows($tableName, $whereArray);
    }
}
function taxonomy_checkbox_list($args = array())
{
    hook_action('taxonomy_checkbox_list');
    hook_filter('taxonomy_checkbox_list_before', $args);
    global $hmtaxonomy;
    $hmdb = new MySQL(true, DB_NAME, DB_HOST, DB_USER, DB_PASSWORD, DB_CHARSET);
    @($key = $args['key']);
    @($parent = $args['parent'] ? $args['parent'] : 0);
    @($default_value = $args['default_value']);
    @($object_id = $args['object_id']);
    if (is_numeric($object_id)) {
        $tableName = DB_PREFIX . "relationship";
        $whereArray = array('object_id' => MySQL::SQLValue($object_id), 'relationship' => MySQL::SQLValue('contax'));
        $hmdb->SelectRows($tableName, $whereArray);
        while ($row = $hmdb->Row()) {
            $default_value[] = $row->target_id;
        }
    }
    if (!is_array($default_value)) {
        $default_value = array();
    }
    $tax = $hmtaxonomy->hmtaxonomy;
    if (isset($tax[$key])) {
        $tableName = DB_PREFIX . "taxonomy";
        $whereArray = array('key' => MySQL::SQLValue($key), 'parent' => MySQL::SQLValue($parent), 'status' => MySQL::SQLValue('public'));
        $hmdb->SelectRows($tableName, $whereArray);
        if ($hmdb->HasRecords()) {
            if ($parent != 0) {
                echo '<ul class="taxonomy_tree_sub_group taxonomy_tree_sub_group_of_' . $parent . '">';
            }
            while ($row = $hmdb->Row()) {
                $taxs[] = $row;
            }
            foreach ($taxs as $tax) {
                if (in_array($tax->id, $default_value)) {
                    $checked = 'checked';
                } else {
                    $checked = '';
                }
                echo '<li data-id="' . $tax->id . '" data-slug="' . $tax->slug . '" class="tax_tree_item tax_tree_item_' . $tax->id . '">';
                echo '<input type="checkbox" name="taxonomy[]" value="' . $tax->id . '" ' . $checked . ' /> ';
                echo '<label>' . $tax->name . '</label>';
                taxonomy_checkbox_list(array('key' => $key, 'parent' => $tax->id, 'default_value' => $default_value));
                echo '</li>';
            }
            if ($parent != 0) {
                echo '</ul>';
            }
        }
    }
}
Esempio n. 13
0
<?php

include_once '../config.php';
include ROOT . "model/Mysql.php";
include 'vheader_aluno.php';
// as pr�ximas 3 linhas s�o respons�veis em se conectar com o bando de dados.
$filter["ALUNO_NOME"] = MySQL::SQLValue('%');
$db = new MySQL();
?>
 
 
 <td width="546" height="300"> 
 
 <?php 
if (!$db) {
    echo " nao conectou <br><br>";
} else {
    echo " conexao OK!<br><br>";
}
echo "Tabela: aluno <p>";
$db->SelectRows("ALUNO");
echo $db->GetHTML();
?>
</td> 

 
 
 
 
// =========================================================================
// $arrayVariable["column name"] = formatted SQL value
$values["Color"] = MySQL::SQLValue("Violet");
$values["Age"] = MySQL::SQLValue(777, MySQL::SQLVALUE_NUMBER);
// Execute the insert
$result = $db->InsertRow("Test", $values);
// If we have an error
if (!$result) {
    // Show the error and kill the script
    $db->Kill();
} else {
    // No error, show the new record's ID
    echo "The new record's ID is: " . $db->GetLastInsertID() . "\n<br />\n";
    // Show the record using the values array to generate the WHERE clause
    // We will use the SelectRows() method to query the database
    $db->SelectRows("Test", $values);
    // Show the results in an HTML table
    echo $db->GetHTML();
}
// =========================================================================
// Example to delete a row (or rows) in a table matching a filter
// =========================================================================
// Now let's delete that record using the same array for the WHERE clause
$db->DeleteRows("Test", $values);
// =========================================================================
// Example to update an existing row into a table
// =========================================================================
// Create an array that holds the update information
// $arrayVariable["column name"] = formatted SQL value
$update["Color"] = MySQL::SQLValue("Red");
$update["Age"] = MySQL::SQLValue(123, MySQL::SQLVALUE_NUMBER);
/** Trả về link thumbnail của file */
function thumbnail_media($id)
{
    $hmdb = new MySQL(true, DB_NAME, DB_HOST, DB_USER, DB_PASSWORD, DB_CHARSET);
    if (isset($id) and is_numeric($id)) {
        $tableName = DB_PREFIX . "media";
        $whereArray = array('id' => MySQL::SQLValue($id));
        $hmdb->SelectRows($tableName, $whereArray);
        $rowCount = $hmdb->RowCount();
        if ($rowCount != 0) {
            $row = $hmdb->Row();
            $file_info = $row->file_info;
            $file_name = $row->file_name;
            $file_folder = $row->file_folder;
            if ($file_folder != '/') {
                $file_folder = '/' . $file_folder . '/';
            }
            $file_info = json_decode($file_info, TRUE);
            if ($file_info['file_is_image'] == TRUE) {
                $thumbnail_src = SITE_URL . FOLDER_PATH . HM_CONTENT_DIR . '/uploads' . $file_folder . $file_info['thumbnail'];
            } else {
                $file_src_name_ext = strtolower($file_info['file_src_name_ext']);
                $file_ext_icon = './' . HM_CONTENT_DIR . '/icon/fileext/' . $file_src_name_ext . '.png';
                if (file_exists($file_ext_icon)) {
                    $thumbnail_src = SITE_URL . FOLDER_PATH . HM_CONTENT_DIR . '/icon/fileext/' . $file_src_name_ext . '.png';
                } else {
                    $thumbnail_src = SITE_URL . FOLDER_PATH . HM_CONTENT_DIR . '/icon/fileext/blank.png';
                }
            }
            return $thumbnail_src;
        }
    }
}
Esempio n. 16
0
<?php

header("Content-type: text/xml");
$hmdb = new MySQL(true, DB_NAME, DB_HOST, DB_USER, DB_PASSWORD, DB_CHARSET);
$sitemap = '';
$sitemap .= '<?xml version="1.0" encoding="UTF-8"?>' . "\r\n";
$sitemap .= '<?xml-stylesheet type="text/xsl" href="' . PLUGIN_URI . 'hm_seo/asset/sitemap.xsl"?>' . "\r\n";
$sitemap .= '<!-- generator="hoamaicms/1.0" -->' . "\r\n";
$sitemap .= '<!-- sitemap-generator-url="hoamaisoft.com" sitemap-generator-version="1.0" -->' . "\r\n";
$sitemap .= '<!-- generated-on="26.09.2015 12:11" -->' . "\r\n";
$sitemap .= '<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\r\n";
//loop
$tableName = DB_PREFIX . "request_uri";
$hmdb->SelectRows($tableName, NULL, NULL, 'object_type', FALSE);
while ($row = $hmdb->Row()) {
    $object_id = $row->object_id;
    $object_type = $row->object_type;
    $uri = $row->uri;
    $uri = urlencode($uri);
    switch ($object_type) {
        case 'content':
            $include_to_sitemap = get_con_val("name=include_to_sitemap&id={$object_id}");
            $sitemap_change_frequency = get_con_val("name=sitemap_change_frequency&id={$object_id}");
            $sitemap_priority = get_con_val("name=sitemap_priority&id={$object_id}");
            $time = get_con_val("name=public_time&id={$object_id}");
            $lastmod = '<lastmod>' . date('Y-m-d H:i:s', $time) . '</lastmod>';
            if ($sitemap_change_frequency == 'auto') {
                $sitemap_change_frequency = get_option(array('section' => 'hm_seo', 'key' => 'content_sitemap_change_frequency', 'default_value' => 'daily'));
            }
            if ($sitemap_priority == 'auto') {
                $sitemap_priority = get_option(array('section' => 'hm_seo', 'key' => 'content_sitemap_priority', 'default_value' => '0.6'));