Executes the given SQL query and returns the records
public Query ( string $sql ) : object | ||
$sql | string | The query string should not end with a semicolon |
return | object | PHP 'mysql result' resource object containing the records on SELECT, SHOW, DESCRIBE or EXPLAIN queries and returns; TRUE or FALSE for all others i.e. UPDATE, DELETE, DROP AND FALSE on all errors (setting the local Error message) |
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); }
/** * delete exp entry * * @param integer $id -> ID of record * @return object */ public function expense_delete($id) { $filter["expenseID"] = MySQL::SQLValue($id, MySQL::SQLVALUE_NUMBER); $table = $this->getExpenseTable(); $query = MySQL::BuildSQLDelete($table, $filter); return $this->conn->Query($query); }
function Query ($query) { if (DATABASE_TYPE == "PGSQL") { return PGSQL::Query ($query); } elseif (DATABASE_TYPE == "MYSQL") { return MySQL::Query ($query); } }
/** * @return array|bool */ public function membership_roles() { $p = $this->kga['server_prefix']; $query = "SELECT a.*, COUNT(DISTINCT b.userID) as count_users FROM `{$p}membershipRoles` a LEFT JOIN `{$p}groups_users` b USING(membershipRoleID) GROUP BY a.membershipRoleID"; $result = $this->conn->Query($query); if ($result == false) { $this->logLastError('membership_roles'); return false; } $rows = $this->conn->RecordsArray(MYSQLI_ASSOC); return $rows; }
function chapter_show_data($id) { $hmdb = new MySQL(true, DB_NAME, DB_HOST, DB_USER, DB_PASSWORD, DB_CHARSET); hook_action('chapter_show_data'); if (!$hmdb->Query("SELECT * FROM " . DB_PREFIX . "content WHERE `status` = 'chapter' AND `parent` = '{$id}' ORDER BY id DESC")) { $hmdb->Kill(); } $array_cha = array(); while ($row = $hmdb->Row()) { $data_cha = content_data_by_id($row->id); $array_cha[] = array('id' => $row->id, 'name' => $row->name, 'slug' => $row->slug, 'public_time' => date('d-m-Y H:i', $data_cha['field']['public_time'])); } $array['chapter'] = $array_cha; return hook_filter('chapter_show_data', json_encode($array, TRUE)); }
function request_suggest($key) { $hmdb = new MySQL(true, DB_NAME, DB_HOST, DB_USER, DB_PASSWORD, DB_CHARSET); global $hmtaxonomy; global $hmcontent; $return = ''; $input_name = hm_post('input', ''); $key = trim($key); $key = str_replace(' ', '-', $key); if ($key != '') { $tableName = DB_PREFIX . 'request_uri'; $hmdb->Query("SELECT * FROM `" . $tableName . "` WHERE `uri` LIKE '%" . $key . "%' LIMIT 10"); while ($row = $hmdb->Row()) { $id = $row->id; $object_id = $row->object_id; $object_type = $row->object_type; $uri = $row->uri; $suggest_label = ''; $object_name = ''; switch ($object_type) { case 'taxonomy': $tax_data = taxonomy_data_by_id($object_id); $tax_key = $tax_data['taxonomy']->key; $taxonomy = $hmtaxonomy->hmtaxonomy; $suggest_label = $taxonomy[$tax_key]['taxonomy_name']; $object_name = get_tax_val('name=name&id=' . $object_id); break; case 'content': $con_data = content_data_by_id($object_id); $con_key = $con_data['content']->key; $content = $hmcontent->hmcontent; $suggest_label = $content[$con_key]['content_name']; $object_name = get_con_val('name=name&id=' . $object_id); break; } $return .= '<li>'; $return .= '<p data-id="' . $id . '" data-input="' . $input_name . '" data-name="' . $object_name . '" object_id="' . $object_id . '" object_type="' . $object_type . '">'; $return .= '<span class="suggest_label">' . $suggest_label . ': </span><b>' . $object_name . '</b>'; $return .= '</p>'; $return .= '</li>'; } } return $return; }
<?php include "../user/config.php"; include "../core/includes/class/mysql.class.php"; $db = new MySQL(false, $sql_dbname, $sql_host, $sql_user, $sql_pass, $sql_charset, $sql_pcon); $db->Open(); $result = $db->Query("CREATE TABLE IF NOT EXISTS `ac_global` (\n\t\t`player_identifier` int(11) NOT NULL AUTO_INCREMENT,\n\t\t`player_auth` varchar(36) COLLATE utf8_unicode_ci NOT NULL,\n\t\t`total_tokens` int(11) NOT NULL,\n\t\t`name` varchar(32) COLLATE utf8_unicode_ci NOT NULL,\n\t\tPRIMARY KEY (`player_identifier`),\n\t\tUNIQUE KEY `player_auth` (`player_auth`)\n\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"); if (!$result) { die("MySQL: " . $db->Error() . ""); } foreach ($servers as $k => $unimportant) { $result = $db->Query("CREATE TABLE IF NOT EXISTS `ac_{$k}_list` (\n\t\t\t`id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t`name` varchar(64) NOT NULL,\n\t\t\t`desc` varchar(256) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,\n\t\t\t`value_id` varchar(32) NOT NULL,\n\t\t\t`icon` varchar(256) NOT NULL,\n\t\t\t`available` int(11) NOT NULL DEFAULT '1',\n\t\t\t`value` int(11) NOT NULL DEFAULT '0',\n\t\t\t`tokens` int(11) NOT NULL DEFAULT '0',\n\t\t\t`max` int(11) NOT NULL DEFAULT '0',\n\t\t\t`created` int(11) NOT NULL DEFAULT '0',\n\t\t\t`cat` int(11) NOT NULL DEFAULT '0',\n\t\t\tPRIMARY KEY (`id`),\n\t\t\tUNIQUE KEY `id` (`id`)\n\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"); if (!$result) { die("There was an error processing the SQL query. Check if any of the server shorts in config file are incorrect. Only alphanumeric values are allowed."); } $result = $db->Query("CREATE TABLE IF NOT EXISTS `ac_{$k}_data` (\n\t\t\t `player_auth` varchar(64) COLLATE utf8_unicode_ci NOT NULL,\n\t\t\t\t`value_id` varchar(32) CHARACTER SET latin1 NOT NULL,\n\t\t\t\t`value_status` int(11) NOT NULL,\n\t\t\t\t`value_extra` int(11) NOT NULL,\n\t\t\t\tPRIMARY KEY (`player_auth`,`value_id`),\n\t\t\t\tKEY `player_auth` (`player_auth`)\n\t\t) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"); if (!$result) { die("There was an error processing the SQL query. Check if any of the server shorts in config file are incorrect. Only alphanumeric values are allowed."); } $result = $db->Query("CREATE TABLE IF NOT EXISTS `ac_{$k}_cats` (\n\t\t\t`cat_id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t`cat_name` varchar(32) NOT NULL,\n\t\t\tPRIMARY KEY (`cat_id`),\n\t\t\tUNIQUE KEY `cat_id` (`cat_id`)\n\t\t) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"); if (!$result) { die("There was an error processing the SQL query. Check if any of the server shorts in config file are incorrect. Only alphanumeric values are allowed."); } } echo "All missing tables (if there were any) were successfully created.";
$User = (string) @$Args['User']; $Password = (string) @$Args['Password']; $DbName = (string) @$Args['DbName']; $Users = (string) @$Args['Users']; #------------------------------------------------------------------------------- $Course = 30; #------------------------------------------------------------------------------- $Params = array('Server' => $Server, 'Port' => $Port, 'User' => $User, 'Password' => $Password, 'DbName' => $DbName); #------------------------------------------------------------------------------- $Link = new MySQL($Params); #------------------------------------------------------------------------------- if (Is_Error($Link->Open())) { return 'Не удалось подключиться к серверу MySQL'; } #------------------------------------------------------------------------------- $Result = $Link->Query(SPrintF('SET NAMES `%s`', $Charset)); if (Is_Error($Result)) { return $Link->GetError(); } #------------------------------------------------------------------------------- if (Is_Error($Link->SelectDB())) { return $Link->GetError(); } #------------------------------------------------------------------------------- $Query = 'SELECT * FROM `users`'; #------------------------------------------------------------------------------- if ($Users) { #----------------------------------------------------------------------------- $Users = Preg_Split('/\\s+/', $Users); #----------------------------------------------------------------------------- $Array = array();
/** 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)); }
include_once 'mysql.class.php'; include_once 'dbf_class.php'; $db = new MySQL(true) or die('Cannot connect to MySQL server. Please check settings in mysql.class.php'); // Begin a new transaction, but this time, let's check for errors. if (!$db->TransactionBegin()) { $db->Kill(); die('Cannot start DB transactions...quitting now.'); } // We'll create a flag to check for any errors $success = true; global $hkdata; //sql building: BE CAREFUL NOT TO USE semicolon inside the sql!!!! $db->TruncateTable("hkmatrix"); //destroy table data $sql = "CREATE TABLE IF NOT EXISTS `hkmatrix` (\n `uid` int(11) NOT NULL AUTO_INCREMENT,\n `custgroup` varchar(4) NULL,\n `refnum` varchar(10) NULL,\n `prodgroup` varchar(254) NULL,\n `supplier` varchar(254) NULL,\n `prodcode` varchar(16) NULL,\n `matrix` varchar(1) NULL,\n `discount` decimal(10,2) NULL,\n `contract` decimal(10,2) NULL,\n `trade` decimal(10,2) NULL,\n `retail` decimal(10,2) NULL,\n `date_on` date DEFAULT NULL,\n `date_off` date DEFAULT NULL,\n\t`break1` decimal(5,2) NULL,\n\t\n\t`break2` decimal(5,2) NULL,\n\t\n\t`break3` decimal(5,2) NULL,\n\t\n\t`break4` decimal(5,2) NULL,\n\t\n\t`break5` decimal(5,2) NULL,\n\t\n\t`break6` decimal(5,2) NULL,\n\t\n\t`break7` decimal(5,2) NULL,\n\t`price1` decimal(10,2) NULL,`price2` decimal(10,2) NULL,`price3` decimal(10,2) NULL,`price4` decimal(10,2) NULL,`price5` decimal(10,2) NULL,`price6` decimal(10,2) NULL,`price7` decimal(10,2) NULL,\n\t `text` varchar(254) NULL,\n\t `type` varchar(4) NULL,\n PRIMARY KEY (`uid`)\n \n) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1"; $results = $db->Query($sql); if (!$results) { die('Error contacting database!' . $sql); } // open in read-write mode if (function_exists('dbase_open')) { // only if php was compiled with dbase support $updatemsg .= "Packing database.<br/>"; $dbo = dbase_open('datastore/hkmatrix.dbf', 2); // expunge the database dbase_pack($dbo); } $dbr = new dbf_class('datastore/hkmatrix.dbf'); $num_rec = $dbr->dbf_num_rec; $field_num = $dbr->dbf_num_field; //print" Num_rec: $num_rec Num_field $field_num <br>";
header('Access-Control-Allow-Credentials: true'); header('Access-Control-Max-Age: 86400'); header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Methods: POST, GET, OPTIONS'); header('Content-type: text/html; charset=utf-8'); } if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') { if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD'])) { header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS"); } if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'])) { header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}"); } } include "mysql.class.php"; $database = new MySQL(); global $database; if ($database->Query("SELECT mensaje, url FROM kiiconnect_compartir ")) { $mensajes = $database->RecordsArray(); $tags = array(); if ($mensajes != false) { foreach ($mensajes as $mensaje) { $tags['url'] = $mensaje['url']; $tags['mensaje'] = $mensaje['mensaje']; } } //echo $database->GetJSON(); echo json_encode($tags); } else { echo "<p>Query Failed</p>"; }
function removewebstock() { echo "Create/clear update DB...\r\n"; $db = new MySQL(true) or die('Cannot connect to MySQL server. Please check settings in mysql.class.php'); $sql = "CREATE TABLE IF NOT EXISTS `import_webstock` (\n `uid` int(11) NOT NULL AUTO_INCREMENT,\n `prodcode` varchar(16) NOT NULL,\n `descr` varchar(254) NOT NULL,\n `category` varchar(254) NULL,\n `url` varchar(254) NULL,\n `price` decimal(10,2) NOT NULL,\n `trade` decimal(10,2) NOT NULL,\n `wholesale` decimal(10,2) NOT NULL,\n `onorder` int(5) NOT NULL DEFAULT '0',\n `stocklevel` decimal(10,0) NOT NULL,\n `updated` date DEFAULT NULL,\n `webready` tinyint(1) NOT NULL DEFAULT '1',\n `supplier` varchar(254) NULL,\n `brand` varchar(254) NOT NULL,\n `model` varchar(254) NOT NULL,\n PRIMARY KEY (`uid`),\n KEY `prodcode` (`prodcode`)\n) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1"; $results = $db->Query($sql); //remove then build table if (!$results) { die('Error contacting database!' . $sql); } $db->TruncateTable("import_webstock"); //destroy table data }
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 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; }
<?php include "mysql.class.php"; $databaseXmltv = new MySQL(); if ($databaseXmltv->Query("SELECT xmltv_canal.id,\n xmltv_canal.nombre as title\n FROM xmltv_canal WHERE activo = 1 ORDER BY orden")) { $canales = $databaseXmltv->GetJSON(); $data = $databaseXmltv->RecordsArray(); } else { $canales = "''"; } ////////////////////////// ?> { "calendars": <?php echo $canales; ?> }
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}"); header('Access-Control-Allow-Credentials: true'); header('Access-Control-Max-Age: 86400'); header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Methods: POST, GET, OPTIONS'); header('Content-type: text/html; charset=utf-8'); } if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') { if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD'])) { header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS"); } if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'])) { header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}"); } } include "mysql.class.php"; $databaseKiiconnect = new MySQL(); global $databaseKiiconnect; // if (isset($_GET["tags"])) { $tags = $_GET["tags"]; $bodytag = '"' . str_replace(",", '","', $tags) . '"'; $consultaTag = "AND tag in ({$bodytag})"; } else { $consultaTag = ""; } if ($databaseKiiconnect->Query("SELECT *\n FROM\n kiiconnect_mensajes\n WHERE activo = 1 {$consultaTag}\n ORDER BY creado DESC ")) { echo $databaseKiiconnect->GetJSON(); } else { echo "<p>Query Failed</p>"; }
* @project 0xSentinel * @author KinG-InFeT * @licence GNU/GPL * * @file sentinel.php * * @link http://0xproject.netsons.org#0xSentinel * */ include "config.php"; include_once "lib/mysql.class.php"; include_once "lib/0xSentinel.class.php"; $sentinel = new Sentinel(); $mysql = new MySQL(); $mysql->Open($db_host, $db_user, $db_pass, $db_name); $ris = $mysql->Query("SELECT * FROM 0xSentinel_settings"); $row = mysql_fetch_array($ris); if ($row['active'] == 1) { if ($row['filter_fpd'] == 1) { $sentinel->check_FPD(); } if ($row['filter_get'] == 1) { $sentinel->check_GET(); } if ($row['filter_post'] == 1) { $sentinel->check_POST(); } if ($row['filter_cookie'] == 1) { $sentinel->check_COOKIE(); } if ($row['filter_session'] == 1) {
* * @link http://0xproject.netsons.org#0xSentinel * */ session_start(); if (file_exists("./install.php")) { header('Location: index.php'); } include "config.php"; include_once "lib/mysql.class.php"; include_once "lib/layout.class.php"; $layout = new layout(); $layout->header(); $mysql = new MySQL(); $mysql->Open($db_host, $db_user, $db_pass, $db_name); $ris = $mysql->Query("SELECT admin_user, admin_pass FROM 0xSentinel_settings"); $row = mysql_fetch_array($ris); if (@$_SESSION['0xSentinel']['admin'] == $row['admin_pass']) { die(header('Location: admin.php')); } if (!empty($_POST['username']) && !empty($_POST['password'])) { $user = $_POST['username']; $pass = md5($_POST['password']); if ($user == $row['admin_user'] && $pass == $row['admin_pass']) { $_SESSION['0xSentinel']['admin'] = $row['admin_pass']; $_SESSION['token'] = md5(rand(1, 999999)); header('Location: admin.php'); } else { print '<script>alert("Dati inseriti Errati"); window.location="login.php";</script>'; } } else {
header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Methods: POST, GET, OPTIONS'); header('Content-type: text/html; charset=utf-8'); } if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') { if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD'])) { header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS"); } if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'])) { header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}"); } } ////////////////////////// include "mysql.class.php"; $databaseXmltv = new MySQL(); if ($databaseXmltv->Query("SELECT xmltv_canal.id,\n xmltv_canal.nombre,\n xmltv_canal.file\n FROM xmltv_canal WHERE activo = 1 ORDER BY orden")) { $canales = $databaseXmltv->GetJSON(); } else { $canales = "''"; } //CONCAT(UNIX_TIMESTAMP (fecha_inicio), '000') as inicio, //CONCAT(UNIX_TIMESTAMP (fecha_fin), '000') as fin, // consulta que me devuelve los programas segun la fecha (ejemplo en fecha actual ) $programas = programacion($fecha); if ($databaseXmltv->Query("SELECT xmltv_programacion.id,\n xmltv_programacion.id_canal,\n xmltv_programacion.id_programa,\n xmltv_programa.titulo,\n IF(length(xmltv_programacion.descripcion) > 0, CONCAT(xmltv_programa.descripcion, ', ' , xmltv_programacion.descripcion) , xmltv_programa.descripcion ) AS descripcion,\n xmltv_programa.tipo,\nDAYOFWEEK(xmltv_programacion.creado),\n CONCAT(CAST(UNIX_TIMESTAMP (CONCAT(CURDATE(), ' ', horario)) AS INT), '000') as inicio,\n CONCAT(CAST(UNIX_TIMESTAMP (CONCAT(CURDATE(), ' ', horario)) AS INT) + xmltv_programacion.duracion * 60, '000') as fin,\n xmltv_programacion.duracion,\n xmltv_programa.file\n FROM xmltv_programacion INNER JOIN xmltv_programa ON xmltv_programacion.id_programa = xmltv_programa.id\n\t\t\t\t\t\t\tWHERE IF(xmltv_programacion.fecha_fin IS NOT NULL, xmltv_programacion.fecha_inicio < CURDATE() AND CURDATE() < xmltv_programacion.fecha_fin , xmltv_programacion.fecha_inicio < CURDATE()) AND\n\t\t\t\t\t\t\txmltv_programa.activo = 1;\n\t\t\t\t\t\t\t")) { $programas = $databaseXmltv->GetJSON(); } else { $programas = "''"; } ////////////////////////// $json = '[{
* * @project 0xSentinel * @author KinG-InFeT * @licence GNU/GPL * * @file banner.php * * @link http://0xproject.netsons.org#0xSentinel * */ include "config.php"; include_once "lib/mysql.class.php"; include_once "lib/layout.class.php"; $mysql = new MySQL(); $mysql->Open($db_host, $db_user, $db_pass, $db_name); $active = $mysql->Query("SELECT * FROM 0xSentinel_settings"); $row = mysql_fetch_array($active); $image = "images/banner.png"; $im = ImageCreateFromPNG($image); imageAlphaBlending($im, TRUE); imageSaveAlpha($im, TRUE); $txt_color = ImageColorAllocate($im, 80, 80, 80); if ($row['active'] == 1) { $color_status = ImageColorAllocate($im, 80, 80, 80); } else { $color_status = ImageColorAllocate($im, 255, 0, 0); } $attack_blocked = intval(mysql_num_rows($mysql->Query("SELECT * FROM 0xSentinel_logs"))); $version = VERSION; ImageString($im, 2, 10, 25, "Version: {$version}", $txt_color); ImageString($im, 2, 10, 37, "Status: ", $txt_color);
define('USERDBD', $userd); define('PASSD', $passd); define('DBASED', $dbased); $dbd = new MySQL(true, DBASED, HOSTD, USERDBD, PASSD); // --------------------------------------------------- // Execute local requete on remote server // --------------------------------------------------- global $db; $fullquery = "SELECT req,id from temprequet where stat=0 "; if (!$db->Query($fullquery)) { $db->Kill($db->Error()); } $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());
} 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>'; }
header('Access-Control-Allow-Methods: POST, GET, OPTIONS'); header('Content-type: text/html; charset=utf-8'); } if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') { if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD'])) { header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS"); } if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'])) { header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}"); } } include "mysql.class.php"; $database = new MySQL(); global $database; if (!isset($_GET["parametro"])) { if ($database->Query("SELECT\n kiiconnect_setting.nombre,\n kiiconnect_setting.tag,\n kiiconnect_setting.descripcion,\n kiiconnect_setting.icono,\n kiiconnect_setting.link,\n kiiconnect_categoria.nombre AS categoria,\n kiiconnect_categoria.id AS id_categoria,\n kiiconnect_categoria.filecategoria,\n kiiconnect_categoria.filecategoria2,\n kiiconnect_categoria.icono AS categoria_icono\n FROM\n kiiconnect_setting\n INNER JOIN kiiconnect_categoria ON kiiconnect_setting.id_categoria = kiiconnect_categoria.id\n WHERE\n activo = 1\n ORDER BY\n orden ASC")) { echo $database->GetJSON(); } else { echo "<p>Query Failed</p>"; } } else { $temp = $database->QueryArray("SELECT\n kiiconnect_categoria.nombre AS categoria,\n kiiconnect_categoria.id AS id_categoria,\n kiiconnect_categoria.iconodev AS categoria_icono,\n kiiconnect_categoria.filecategoriadev AS filecategoria\n FROM\n kiiconnect_categoria\n WHERE\n activo = 1\n ORDER BY orden2", MYSQL_ASSOC); $temp2 = array(); foreach ($temp as $index => $categoria) { $categoria_id = $categoria['id_categoria']; // CONCAT('" . '<span style="font-weight:bold">' ." ', kiiconnect_setting.nombre, '</span>') AS nombre, $itemsCategoria = $database->QueryArray("SELECT\n kiiconnect_setting.nombre,\n kiiconnect_setting.tag,\n kiiconnect_setting.descripcion,\n kiiconnect_setting.icono,\n kiiconnect_setting.file,\n kiiconnect_setting.link\n FROM\n kiiconnect_setting\n WHERE\n activo = 1 AND id_categoria = {$categoria_id}\n ORDER BY\n orden ASC", MYSQL_ASSOC); if ($itemsCategoria != false) { $categoria['items'] = $itemsCategoria; $temp2[] = $categoria; }
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)); }
function getCategoryStringForLayeredTemplate() { $db = new MySQL(); $sql = "SELECT id_category FROM ps_category WHERE id_category > 1"; $result = $db->Query($sql); while (!$db->EndOfSeek()) { $row[] = $db->Row(); } $categoryArray = array(); foreach ($row as $id_category) { $categoryArray[] = $id_category->id_category; } return $categoryArray; }
/** * Metodo per fare il TRUNCATE della tabella passato come parametro * * @param String $tablename Nome della tabella */ function truncateTable($tablename) { $db = new MySQL(); $sql = "TRUNCATE `" . $tablename . "`"; $db->Query($sql); }
`Age` int(10) default NULL, PRIMARY KEY (`TestID`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -------------------------------------------- */ // --- Open the database -------------------------------------------- // (Also note that you can fill in the variables in the top of the class // if you want to automatically connect when the object is created. If // you fill in the values when you create the obect, this is not needed.) if (!$db->Open("test", "localhost", "root", "password")) { $db->Kill(); } echo "You are connected to the database<br />\n"; // --- Insert a new record ------------------------------------------ $sql = "INSERT INTO Test (Color, Age) Values ('Red', 7)"; if (!$db->Query($sql)) { $db->Kill(); } echo "Last ID inserted was: " . $db->GetLastInsertID(); // --- Or insert a new record with transaction processing ----------- $sql = "INSERT INTO Test (Color, Age) Values ('Blue', 3)"; $db->TransactionBegin(); 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)
/** * Metodo per cancellare immagini al prodotto associata * * @param int $id_product Id del prodotto */ function reinitProductImage($id_product) { $sql = "DELETE FROM ps_image WHERE id_product = {$id_product}"; $db = new MySQL(); $db->Query($sql); }
function enableScontiQt() { $sql_1 = "UPDATE ps_configuration SET `value` = '1' WHERE `name` = 'PS_SPECIFIC_PRICE_FEATURE_ACTIVE'"; $db = new MySQL(); $db->Query($sql_1); $sql = "UPDATE ps_configuration SET `value` = NULL WHERE `name` = 'PS_PACK_FEATURE_ACTIVE'"; $db->Query($sql); }
if (count($parametros) > 0) { $parametros[0] != "0" ? $richpage = $parametros[0] : ($richpage = ""); $parametros[1] != "0" ? $tag = $parametros[1] : ($tag = ""); $parametros[2] != "0" ? $l = $parametros[2] : ($l = ""); } else { $richpage = ""; $tag = ""; } } else { $header = ""; $richpage = ""; $tag = ""; } // validar que el mismo registro no exista //1 recuperamos el ultimo registro if ($database->Query("SELECT MAX(creado) as creado FROM kiiconnect_mensajes;")) { $data = $database->RecordsArray(); $fechaCreado = $data[0]['creado']; //2 comparamos si existio otro registro similar en el tiempo $sql = "SELECT NOW() as fecha"; if ($database->Query($sql)) { // if ($database->Query("select * from kiiconnect_mensajes where creado > date_sub('2015-09-23 11:16:30', interval 1 minute) ;")) { $data = $database->RecordsArray(); $fechaServidor = $data[0]['fecha']; $datetime1 = new DateTime($fechaCreado); $datetime2 = new DateTime($fechaServidor); $diferencia = $datetime1->diff($datetime2); if ($diferencia->y == 0 && $diferencia->m == 0 && $diferencia->d == 0 && $diferencia->h == 0 && $diferencia->i == 0 && $diferencia->s == 0) { // registro en el mismo minuto se omite } else { // registro se inserta