/** 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; } }
/** * Check if a global role gives permission for a specific action. * * @param integer $roleID the ID of the global role * @param string $permission name of the action / permission * @return bool true if permissions is granted, false otherwise */ public function global_role_allows($roleID, $permission) { $filter['globalRoleID'] = MySQL::SQLValue($roleID, MySQL::SQLVALUE_NUMBER); $filter[$permission] = 1; $columns[] = "globalRoleID"; $table = $this->kga['server_prefix'] . "globalRoles"; $result = $this->conn->SelectRows($table, $filter, $columns); if ($result === false) { $this->logLastError('global_role_allows'); return false; } $result = $this->conn->RowCount() > 0; /* // TODO should we add a setting for debugging permissions? Kimai_Logger::logfile("Global role $roleID gave " . ($result ? 'true' : 'false') . " for $permission."); */ return $result; }
public function dupeCheck($name) { $db = new MySQL(true, 'color64', 'localhost', 'color64', 'nu5Jc4JdtZK4RCHH'); $q = $db->Query("SELECT `id` FROM `users`"); $allrecords = $db->RowCount(); $q = $db->Query("SELECT `id` FROM `users` WHERE `name` LIKE '" . $name . "';"); if ($db->RowCount() > 0) { $dupes = $db->Row()->id; } else { $dupes = 0; } return array('total' => $allrecords, 'dupe' => $dupes); }
} $nbrlocalreq = $db->RowCount(); while (!$db->EndOfSeek()) { $row = $db->Row(); $dbd->Query($row->req); } $db->Query("update temprequet set stat=1 where stat=0"); // --------------------------------------------------- // Execute Remote requete on locoal server // --------------------------------------------------- global $db; $fullquery = "SELECT req,id from temprequet where stat=0 "; if (!$dbd->Query($fullquery)) { $dbd->Kill($dbd->Error()); } $nbrremotreq = $dbd->RowCount(); while (!$dbd->EndOfSeek()) { $row = $dbd->Row(); if (!$db->Query($row->req)) { $db->Kill($db->Error()); } else { $dbd->Query("update temprequet set stat=1 where id=" . $row->id); } } // --------------------------------------------------- // Insert log Last update // --------------------------------------------------- $nbrreq = $nbrlocalreq + $nbrremotreq; $lastmaj = "Insert into maj_sys(nbrreq,user)values({$nbrreq}," . $_SESSION['userid'] . ")"; if (!$db->Query($lastmaj)) { $db->Kill($lastmaj);
function backupDatabase($dbName, $backupStructure = true, $backupData = true, $backupFile = null) { $columnName = 'Tables_in_' . $dbName; $this->done = false; $this->output .= "-- SQL Dump File \n"; $this->output .= "-- Generation Time: " . date('M j, Y') . " at " . date('h:i:s A') . " \n\n"; $this->output .= "-- \n"; $this->output .= "-- Database: `{$dbName}` \n"; $this->output .= "-- \n\n"; $conn = new MySQL(true, DBNAME, DBHOST, DBUSER, DBPASS, "", true); $strTables = 'SHOW TABLES'; $conn->Query($strTables); $cntTables = $conn->RowCount(); if ($cntTables) { $conn->MoveFirst(); while (!$conn->EndOfSeek()) { $rsTables = $conn->Row(); if ($backupStructure) { $this->dumpTableStructure($rsTables->{$columnName}); } if ($backupData) { $this->dumpTableData($rsTables->{$columnName}); } } } else { $this->output .= "-- \n"; $this->output .= "-- No tables in {$dbName} \n"; $this->output .= "-- \n"; } if (!is_null($backupFile)) { $this->dumpToFile($backupFile); } $this->done = true; }
/** bảng danh sách thành viên */ function user_show_data($user_group, $perpage) { $hmdb = new MySQL(true, DB_NAME, DB_HOST, DB_USER, DB_PASSWORD, DB_CHARSET); hook_action('user_show_data'); $request_paged = hm_get('paged', 1); $paged = $request_paged - 1; $offset = $paged * $perpage; $limit = "LIMIT {$perpage} OFFSET {$offset}"; if (!$hmdb->Query("SELECT * FROM " . DB_PREFIX . "users WHERE `user_group` = '{$user_group}' ORDER BY id DESC {$limit}")) { $hmdb->Kill(); } if ($hmdb->HasRecords()) { /* Trả về các user */ while ($row = $hmdb->Row()) { $array_use[] = array('id' => $row->id, 'user_nicename' => $row->user_nicename, 'user_role' => user_role_id_to_nicename($row->user_role)); } $array['user'] = $array_use; /* Tạo pagination */ $hmdb->Query(" SELECT * FROM " . DB_PREFIX . "users WHERE `user_group` = '{$user_group}' "); $total_item = $hmdb->RowCount(); $total_page = ceil($total_item / $perpage); $first = '1'; if ($request_paged > 1) { $previous = $request_paged - 1; } else { $previous = $first; } if ($request_paged < $total_page) { $next = $request_paged + 1; } else { $next = $total_page; } $array['pagination'] = array('first' => $first, 'previous' => $previous, 'next' => $next, 'last' => $total_page, 'total' => $total_item, 'paged' => $request_paged); } else { $array['user'] = array(); $array['pagination'] = array(); } return hook_filter('user_show_data', json_encode($array, TRUE)); }
/** * Metodo se già esiste il raggrupamento per immagine * * @param int $id_product Id del prodotto * @return boolean TRUE se esiste, FALSE non c'è */ function checkIfAlreayExistsGroupPrID($id_product) { $sql = "SELECT * FROM erp_image_group WHERE id_product = {$id_product}"; $db = new MySQL(); $result = $db->QuerySingleRow($sql); if ($db->RowCount() > 0) { return TRUE; } else { return FALSE; } }
/** * Metodo per a creazione del file di indirizzi (indirizzi fatturazione - spedizione) */ function getIndirizzi() { /* * La richiesta � quella di gestire anche un 4� file, denominato FWINDIRIZZI, che contenga tutti gli indirizzi di spedizione. * * */ $query = "SELECT \n\t\tid_address,\n\t customer_code,\n\t\tcompany,\n\t\tfirstname,\n\t\tlastname,\n\t\tCONCAT(address1, ' ', address2) as full_address,\n\t\tpostcode,\n\t\tcity,\n\t\tstate_name,\n\t\tphone,\n\t\tphone_mobile,\n\t\tvat_number\n\t\t\n\t\tFROM ps_address \n\t\tLEFT JOIN (SELECT code as customer_code, id_customer from ps_customer) AS ps_customer_joined ON ps_customer_joined.id_customer = ps_address.id_customer\n\t\tLEFT JOIN (SELECT name as state_name, id_state from ps_state) as ps_state_joined ON ps_state_joined.id_state = ps_address.id_state\n\t\t\n\t\tWHERE ((synch = 0)AND(NOT(alias LIKE 'fatturazione')))"; $db = new MySQL(); $db->Query($query); $row = NULL; if ($db->RowCount() > 0) { while (!$db->EndOfSeek()) { $row[] = $db->Row(); } } foreach ($row as $anag) { /* DOC: 2.1) TABELLA FWINDIRIZZI (1) La tabella FWINDIRIZZI potr� avere un tracciato record ricavato da quello della tabella �ps_address� di Presta Shop: Campo Valori Chiave Descrizione campo ID_Address int si Numero univoco indirizzo CdCustomer char(50) no Codice del cliente, ricavato dalla tabella ps_customer Company char(64) no Ragione sociale Cognome char(32) no Cognome, da concatenare con Nome e importare in DestDiv.Des2Dest Nome char(32) no Vedi sopra Address char(128) no Indirizzo Zip char(12) no Codice Avviamento Postale City char(64) no Localit� NB. -> ripetizione. elimino => City char(64) no Localit� Prov char(5) no Sigla Provincia, ricavato da ID_State o ID_Country ? Phone char(32) no Telefono PhoneMob char(32) no Cellulare, da importare in Contatto VATnum char(32) no Partita IVA */ $stringa = null; $stringa[] = $anag->id_address; $stringa[] = $anag->customer_code; $stringa[] = !empty($anag->company) ? $anag->company : "-Senza Ragione Sociale-"; $stringa[] = !empty($anag->lastname) ? $anag->lastname : "-Senza Cognome-"; $stringa[] = !empty($anag->firstname) ? $anag->firstname : "-Senza Nome-"; $stringa[] = !empty($anag->full_address) ? $anag->full_address : "-Senza Indirizzo-"; $stringa[] = $anag->postcode; $stringa[] = $anag->city; $stringa[] = $anag->state_name; $stringa[] = $anag->phone; $stringa[] = $anag->phone_mobile; $stringa[] = !empty($anag->vat_number) ? $anag->vat_number : "-Senza Partita Iva-"; file_put_contents($this->fileFWINDIRIZZI, iconv(mb_detect_encoding(implode("§", $stringa), mb_detect_order(), true), "UTF-8", implode("§", $stringa)) . "\r\n", FILE_APPEND); $this->setAnagraficaSynchronized($anag->id_address); /* $stringa = null; $stringa[] = $this->fillCodeClientiWithZero($this -> getCodeClienti(), $anag -> id_customer); // CDute [0] $appo = null; $appo = $this -> getSIngleAnagFromId($anag -> id_customer); if (!empty($appo -> company)) { $stringa[] = $appo -> company; // DSRaso [1] } else { $stringa[] = "-Senza Ragione Sociale-"; } if (!empty($anag -> lastname)) { $stringa[] = $anag -> lastname; // DSCognome [2] } else { $stringa[] = "-Senza Cognome-"; } if (!empty($anag -> firstname)) { $stringa[] = $anag -> firstname; // DSnome [3] } else { $stringa[] = "-Senza Nome-"; } if (!empty($appo -> vat_number)) { $stringa[] = $appo -> vat_number; // DSpiva [4] } else { $stringa[] = "-Senza Partita Iva-"; } if (!empty($appo -> dni)) { $stringa[] = $appo -> dni; // DScod_fis [5] } else { $stringa[] = "-Senza Codice Fiscale-"; } $stringa[] = $appo -> address1; // DSindi [6] $stringa[] = $appo -> postcode; // DScap [7] $stringa[] = $appo -> city; // DSloca [8] $stringa[] = $this -> getStateFromId($appo -> id_state); //$stringa[] = ""; // DSprov [9] $stringa[] = $appo -> phone; // DStel [10] $stringa[] = $appo -> phone_mobile; // DScell [11] $stringa[] = ""; // DSfax [12] $stringa[] = $anag -> email; // DSemail [13] $stringa[] = ""; // null [14] $stringa[] = ""; // null [15] $stringa[] = "IT"; // DSnazione [16] $stringa[] = ""; // MMNota [17] $stringa[] = $anag -> email; // DSlogin [18] $stringa[] = ""; // DSpwd [19] * file_put_contents($this -> fileFWINDIRIZZI, iconv(mb_detect_encoding(implode("§", $stringa), mb_detect_order(), true), "UTF-8", implode("§", $stringa)) . "\r\n", FILE_APPEND); $this -> unselectSingleAnag($anag -> id_customer, $this->fillCodeClientiWithZero($this -> getCodeClienti(), $anag -> id_customer)); */ } }
if ($db->Query($sql)) { $db->TransactionEnd(); echo "Last ID inserted was: " . $db->GetLastInsertID() . "<br /><br />\n"; } else { $db->TransactionRollback(); echo "<p>Query Failed</p>\n"; } // --- Query and show the data -------------------------------------- // (Note: $db->Query also returns the result set) if ($db->Query("SELECT * FROM Test")) { echo $db->GetHTML(); } else { echo "<p>Query Failed</p>"; } // --- Getting the record count is easy ----------------------------- echo "\n<p>Record Count: " . $db->RowCount() . "</p>\n"; // --- Loop through the records ------------------------------------- while ($row = $db->Row()) { echo $row->Color . " - " . $row->Age . "<br />\n"; } // --- Loop through the records another way ------------------------- $db->MoveFirst(); while (!$db->EndOfSeek()) { $row = $db->Row(); echo $row->Color . " - " . $row->Age . "<br />\n"; } // --- Loop through the records with an index ----------------------- for ($index = 0; $index < $db->RowCount(); $index++) { $row = $db->Row($index); echo "Row " . $index . ":" . $row->Color . " - " . $row->Age . "<br />\n"; }
function query_content($args = array()) { global $hmcontent; $hmdb = new MySQL(true, DB_NAME, DB_HOST, DB_USER, DB_PASSWORD, DB_CHARSET); hook_filter('before_query_content', $args); hook_action('query_content'); if (!is_array($args)) { parse_str($args, $args); } /** Lọc theo content_key */ if (isset($args['content_key'])) { /** Nếu yêu cầu content key thì lấy các id có key như query yêu cầu */ $content_key = $args['content_key']; /** Nếu content key là một mảng */ if (is_array($content_key)) { $where_key = ''; $i = 0; foreach ($content_key as $key) { if ($i == 0) { $where_key .= " `key` = '" . $key . "' "; } else { $where_key .= " OR `key` = '" . $key . "' "; } $i++; } $where_content_key = "WHERE " . $where_key; } else { $where_content_key = "WHERE `key` = '" . $content_key . "'"; } } else { /** Không yêu cầu content key, kiểm tra xem có đang ở template taxonomy không */ if (is_taxonomy() == TRUE) { $taxonomy_id = get_id(); $content_key = taxonomy_get_content_key($taxonomy_id); if ($content_key != FALSE) { $where_content_key = "WHERE `key` = '" . $content_key . "'"; } } else { $where_content_key = ''; } } $hmdb->Release(); $query_content_key = "SELECT `id` FROM `" . DB_PREFIX . "content` " . $where_content_key; /** Lọc theo taxonomy */ $where_taxonomy = ''; if (isset($args['taxonomy'])) { /** Nếu yêu cầu trong một taxonomy nhất định thì lấy các object_id có relationship như query yêu cầu */ $taxonomy_id = $args['taxonomy']; /** Nếu taxonomy là một mảng */ if (is_array($taxonomy_id)) { $implode = implode($taxonomy_id, ','); if ($implode != '') { $where_taxonomy = ' WHERE `target_id` IN (' . $implode . ') '; } } else { $where_taxonomy = 'WHERE `target_id` = ' . $taxonomy_id; } } else { /** Không yêu cầu taxonomy nhất định, kiểm tra xem có đang ở template taxonomy không */ if (is_taxonomy() == TRUE) { $taxonomy_id = get_id(); $where_taxonomy = 'WHERE `target_id` = ' . $taxonomy_id; } } if ($where_taxonomy != '') { $hmdb->Release(); $query_in_taxonomy = "SELECT `object_id` FROM `" . DB_PREFIX . "relationship` " . $where_taxonomy . " AND `relationship` = 'contax'"; } /** Lọc theo field */ if (isset($args['field_query'])) { $field_query = $args['field_query']; } else { $field_query = array(array('field' => 'status', 'compare' => '=', 'value' => 'public'), array('field' => 'public_time', 'compare' => '<=', 'value' => time())); } $all_field_query = array(); foreach ($field_query as $item) { /** check đủ điều kiện tạo field query */ if (isset($item['field']) and isset($item['compare']) and isset($item['value'])) { $field = $item['field']; $compare = $item['compare']; $value = $item['value']; $numerically = FALSE; /** build query */ if (is_numeric($value)) { $value_query = $value; } else { $value_query = "'{$value}'"; } if ($compare == 'like%') { $all_field_query[$field] = " ( `name` = '{$field}' AND `val` LIKE '%{$value}%' )"; } else { $all_field_query[$field] = " ( `name` = '{$field}' AND `val` {$compare} {$value_query} )"; } } } /** nếu size của mảng chứa các kết quả của các field query >= 2 */ $size = sizeof($all_field_query); $query_field = "SELECT `object_id` FROM `" . DB_PREFIX . "field` WHERE"; if ($size > 1) { if (isset($args['field_query_relation'])) { $field_query_relation = $args['field_query_relation']; } else { $field_query_relation = 'and'; } switch ($field_query_relation) { case 'or': $i = 0; foreach ($all_field_query as $single_field_query) { if ($i == 0) { $query_field .= " " . $single_field_query . " "; } else { $query_field .= " OR " . $single_field_query . " "; } $i++; } break; case 'and': $i = 0; foreach ($all_field_query as $single_field_query) { if ($i == 0) { $query_field .= " " . $single_field_query . " "; } else { $query_field .= " OR " . $single_field_query . " "; } $i++; } $query_field .= " GROUP BY `object_id` HAVING COUNT(*) = {$size} "; break; } /** * Đưa ra kết quả dựa trên mối quan hệ giữa các field query ( field_query_relation ) * ( thỏa mãn tất cả các field query hay chỉ cần đáp ứng được 1 trong những field query ) */ } else { $query_field = $query_field . array_shift(array_values($all_field_query)); } /** Kiểm tra yêu cầu kết hợp kết quả từ content key, in taxonomy, field query là tất cả hay chỉ 1 */ if (isset($args['join'])) { $join = $args['join']; } else { $join = 'and'; } $query_join = ''; switch ($join) { case 'or': if ($query_content_key) { $query_join .= " AND `object_id` IN (" . $query_content_key . ") "; } if ($query_in_taxonomy) { $query_join .= " OR `object_id` IN (" . $query_in_taxonomy . ") "; } $query_join .= " OR `object_id` IN (" . $query_field . ") "; break; case 'and': if ($query_content_key) { $query_join .= " AND `object_id` IN (" . $query_content_key . ") "; } if ($query_in_taxonomy) { $query_join .= " AND `object_id` IN (" . $query_in_taxonomy . ") "; } $query_join .= " AND `object_id` IN (" . $query_field . ") "; break; default: if ($query_content_key) { $query_join .= " AND `object_id` IN (" . $query_content_key . ") "; } if ($query_in_taxonomy) { $query_join .= " AND `object_id` IN (" . $query_in_taxonomy . ") "; } $query_join .= " AND `object_id` IN (" . $query_field . ") "; } /** Kết thúc các query lấy các content id thỏa mãn yêu cầu */ /** Order theo 1 field và limit */ if (isset($args['order'])) { $order_by = $args['order']; } else { $order_by = 'public_time,desc,number'; } if (isset($args['limit'])) { $limit = $args['limit']; } else { $limit = get_option(array('section' => 'system_setting', 'key' => 'post_per_page', 'default_value' => '12')); } if (isset($args['offset']) and is_numeric($args['offset'])) { $offset = $args['offset']; } else { $offset = 0; } if (isset($args['paged'])) { $paged = $args['paged']; } else { $paged = get_current_pagination(); } $paged = $paged - 1; if ($paged < 0) { $paged = 0; } /** Tạo query ORDER */ $ex = explode(',', $order_by); $ex = array_map("trim", $ex); $order_field = $ex[0]; $order = strtoupper($ex[1]); if (isset($ex[2])) { $numerically = $ex[2]; } else { $numerically = FALSE; } if ($numerically == 'number') { $order_query = " AND `name` = '" . $order_field . "' ORDER BY CAST(val AS unsigned) " . $order . " "; } else { $order_query = " AND `name` = '" . $order_field . "' ORDER BY `val` " . $order . " "; } /** Tạo query LIMIT */ if (is_numeric($limit)) { $limit_query = " LIMIT {$limit} "; } else { $limit_query = ''; } /** Tạo query OFFSET */ if ($limit == FALSE) { $offset_query = ''; } else { $offset_query_page = $paged * $limit; $offset_query_page = $offset_query_page + $offset; $offset_query = " OFFSET {$offset_query_page} "; } /** Tạo câu lệnh select từ chuỗi các id thỏa mãn */ $result = array(); $sql = "SELECT `object_id`" . " FROM `" . DB_PREFIX . "field`" . " WHERE `object_type` = 'content'" . " " . $query_join . " " . " " . $order_query . " "; $hmdb->Query($sql); $total_result = $hmdb->RowCount(); $sql = "SELECT `object_id`" . " FROM `" . DB_PREFIX . "field`" . " WHERE `object_type` = 'content'" . " " . $query_join . " " . " " . $order_query . " " . $limit_query . " " . $offset_query . " "; $hmdb->Query($sql); $base = get_current_uri(); if ($base == '') { $base = '/'; } $hmcontent->set_val(array('key' => 'total_result', 'val' => $total_result)); $hmcontent->set_val(array('key' => 'paged', 'val' => $paged + 1)); $hmcontent->set_val(array('key' => 'perpage', 'val' => $limit)); $hmcontent->set_val(array('key' => 'base', 'val' => $base)); while ($row = $hmdb->Row()) { $result[] = $row->object_id; } return $result; }
function checkIfAnagraficaFatturazioneEsiste($vs_code) { $sql = "SELECT * FROM ps_address WHERE vs_code = '{$vs_code}' AND alias = 'fatturazione'"; $db = new MySQL(); $result = $db->QuerySingleRow($sql); if ($db->RowCount() > 0) { return $result->id_address; } else { return 0; } }
/** * Metodo utilizzato per recuperare ultimo valore di position all'interno della tabella ps_category_shop * * @return int $position Ultimo valore di position presente */ function getCategoryShopLastPosition() { $db = new MySQL(); $sql = "SELECT position FROM ps_category_shop WHERE id_category > 2 ORDER BY position DESC"; $result = $db->QuerySingleRow($sql); if ($db->RowCount() > 0) { return $result->position + 1; } else { return 1; } }
/** 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; } } }
} // getting total number records without any search $sql = "SELECT * FROM `employee` "; $sqlTot .= $sql; $sqlRec .= $sql; //concatenate search sql if value exist if (isset($where) && $where != '') { $sqlTot .= $where; $sqlRec .= $where; } $sqlRec .= " ORDER BY " . $columns[$params['order'][0]['column']] . " " . $params['order'][0]['dir'] . " LIMIT " . $params['start'] . " ," . $params['length'] . " "; if (!$db->Query($sqlTot)) { $db->Kill($db->Error()); } //$queryTot = mysqli_query($conn, $sqlTot) or die("database error:". mysqli_error($conn)); $totalRecords = $db->RowCount(); //$totalRecords = mysqli_num_rows($queryTot); if (!$db->Query($sqlRec)) { $db->Kill($db->Error()); } //$queryRecords = mysqli_query($conn, $sqlRec) or die("error to fetch employees data"); //iterate on results row and create new index array of data while (!$db->EndOfSeek()) { $row = $db->RowValue(); $data[] = $row; } //while( $row = mysqli_fetch_row($queryRecords) ) { //$data[] = $row; //} $json_data = array("draw" => intval($params['draw']), "recordsTotal" => intval($totalRecords), "recordsFiltered" => intval($totalRecords), "data" => $data); echo json_encode($json_data);
<?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>';
} if (isset($_GET['url'])) { /************************* categoria **************************/ $bd = new MySQL(); $bd->Query('SELECT CATEGORIA_NOME,CATEGORIA_CDG FROM CATEGORIA'); if ($bd->RowCount() > 0) { while ($row = mysqli_fetch_array($bd->last_result, MYSQLI_ASSOC)) { $cats[] = array("cdg" => $row['CATEGORIA_CDG'], "url" => removeAcentos(utf8_decode($row['CATEGORIA_NOME']), '-')); } } foreach ($cats as $C => $c) { //echo $c['cdg'].' - '.$c['url'].'<br>'; $bd->Query('UPDATE CATEGORIA SET CATEGORIA_URL = "' . $c['url'] . '" WHERE CATEGORIA_CDG = ' . $c['cdg'] . ' '); } echo 'urls tabela CATEGORIA ok.<br>'; /************************* noticia **************************/ $bd = new MySQL(); $bd->Query('SELECT NOTICIA_TITULO,NOTICIA_CDG FROM NOTICIA'); if ($bd->RowCount() > 0) { while ($row = mysqli_fetch_array($bd->last_result, MYSQLI_ASSOC)) { $cats[] = array("cdg" => $row['NOTICIA_CDG'], "url" => removeAcentos(utf8_decode($row['NOTICIA_TITULO']), '-')); } } foreach ($cats as $C => $c) { //echo $c['cdg'].' - '.$c['url'].'<br>'; $bd->Query('UPDATE NOTICIA SET NOTICIA_URL = "' . $c['url'] . '" WHERE NOTICIA_CDG = ' . $c['cdg'] . ' '); } echo 'urls tabela NOTICIA ok.<br>'; }
function content_show_data($key, $status, $perpage) { global $hmcontent; $hmdb = new MySQL(true, DB_NAME, DB_HOST, DB_USER, DB_PASSWORD, DB_CHARSET); hook_action('content_show_data'); $request_paged = hm_get('paged', 1); $paged = $request_paged - 1; $offset = $paged * $perpage; $limit = "LIMIT {$perpage} OFFSET {$offset}"; if (!$hmdb->Query("SELECT * FROM " . DB_PREFIX . "content WHERE `key` = '{$key}' AND status = '{$status}' ORDER BY id DESC {$limit}")) { $hmdb->Kill(); } if ($hmdb->HasRecords()) { /* Trả về các content */ while ($row = $hmdb->Row()) { $array_con[] = array('id' => $row->id, 'name' => $row->name, 'slug' => $row->slug); } $array['content'] = $array_con; /* Tạo pagination */ $hmdb->Query(" SELECT * FROM " . DB_PREFIX . "content WHERE `key` = '{$key}' AND status = '{$status}' "); $total_item = $hmdb->RowCount(); $total_page = ceil($total_item / $perpage); $first = '1'; if ($request_paged > 1) { $previous = $request_paged - 1; } else { $previous = $first; } if ($request_paged < $total_page) { $next = $request_paged + 1; } else { $next = $total_page; } $array['pagination'] = array('first' => $first, 'previous' => $previous, 'next' => $next, 'last' => $total_page, 'total' => $total_item, 'paged' => $request_paged); $all_content = $hmcontent->hmcontent; if (isset($all_content[$key]['chapter']) and $all_content[$key]['chapter'] == TRUE) { $array['chapter'] = TRUE; } else { $array['chapter'] = FALSE; } } else { $array['content'] = array(); $array['pagination'] = array(); $array['chapter'] = FALSE; } return hook_filter('content_show_data', json_encode($array, TRUE)); }
$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';
/** * Metodo utilizzato per controllare se il campo è da aggiornare o inserire * nella tabella vsecommerce_info * * @param String $field_name Nome del parametro * @return boolean Se TRUE il campo field_name esiste nella cartella vsecommerce_info, falso il campo non esiste */ function checkInfoExists($field_name) { $sql = "SELECT * FROM vsecommerce_info WHERE field_name = '{$field_name}'"; $db = new MySQL(); $db->Query($sql); if ($db->RowCount() > 0) { return TRUE; } else { return FALSE; } }
function isTherePriceHighPriority($id_product, $id_customer) { $sql = "SELECT * FROM ps_specific_price WHERE id_customer = {$id_customer} AND id_product = {$id_product}"; $db = new MySQL(); $db->Query($sql); if ($db->RowCount() > 0) { return true; } else { return false; } }
// of the mysql.class.php file and these parameters are all optional. // See the top section of the mysql.class.php file for more info. $db = new MySQL(true, "test", "localhost", "root", "password"); // This checks for errors and if there is one, terminates the script // while showing the last MySQL error. if ($db->Error()) { $db->Kill(); } // Or use: if ($db->Error()) die($db->Error()); // Or: if ($db->Error()) echo $db->Error(); // Execute our query if (!$db->Query("SELECT * FROM Test")) { $db->Kill(); } // Let's show how many records were returned echo $db->RowCount() . " records returned.<br />\n<hr />\n"; // Loop through the records using the MySQL object (prefered) $db->MoveFirst(); while (!$db->EndOfSeek()) { $row = $db->Row(); echo "Row " . $db->SeekPosition() . ": "; echo $row->Color . " and " . $row->Age . "<br />\n"; } // ========================================================================= // The rest of this tutorial covers addition methods of getting to the data // and is completely optional. // ========================================================================= echo "<hr />\n"; // --------------------------------------------------------- // Loop through the records using a counter and display the values for ($index = 0; $index < $db->RowCount(); $index++) {