public function Insert($params) { //prepair function varaibles $table = isset($params['table']) ? $params['table'] : false; $insertItems = isset($params['insert_items']) ? $params['insert_items'] : false; $execute = isset($params['execute']) ? $params['execute'] : true; $print = isset($params['print']) ? $params['print'] : false; //Preform Insert on table if (!empty($insertItems)) { //create sql from items provided $insert = $this->buildInsert($table, $insertItems); //print sql if ($print) { SERVER::dump($insert['statement']); } //execute sql if ($execute == true) { //connect if not already $this->Connect(); //prepair assembled statement $theStatement = $this->connection->prepare($insert['statement']); //Dynamicly Bind assembled params to statement call_user_func_array(array($theStatement, 'bind_param'), $insert['bindParams']); //execute statement $sucess = $theStatement->execute(); //return sucess state $theStatement->close(); return $sucess; } } }
function SHOW_PRETTY($result) { $pretty = SERVER::json_pretty($result); //convert structure or json SERVER::dump($pretty, 'JSON'); //dump string to the screen }
public function MySQLJoinFetchRow($params, &$debug = false) { $query = isset($params['query']) && !empty($params['query']) ? $params['query'] : false; $query = isset($params) && !is_array($params) ? $params : $query; $order_by = isset($params['order_by']) && !empty($params['order_by']) ? $params['order_by'] : false; $condition = isset($params['condition']) && !empty($params['condition']) ? strtoupper($params['condition']) : 'AND'; $operator = isset($params['operator']) && !empty($params['operator']) ? strtoupper($params['operator']) : '='; $order = isset($params['order']) && !empty($params['order']) ? $params['order'] : false; $by = isset($params['by']) && !empty($params['by']) ? $params['by'] : false; $params = $this->PrepForStorage($params); $join_type = isset($params['join_type']) && $params['join_type'] ? $params['join_type'] : 'left'; $left_table['select_items'] = SERVER::isthere($params['left_table']['select_items']); $left_table['join'] = SERVER::isthere($params['left_table']['join']); $left_table['table'] = SERVER::isthere($params['left_table']['table']); $left_table['where_items'] = SERVER::isthere($params['left_table']['where_items']); $right_table['select_items'] = SERVER::isthere($params['right_table']['select_items']); $right_table['join'] = SERVER::isthere($params['right_table']['join']); $right_table['table'] = SERVER::isthere($params['right_table']['table']); $right_table['where_items'] = SERVER::isthere($params['right_table']['where_items']); $row_key = isset($params['row_key']) && $params['row_key'] ? $params['row_key'] : false; $random = isset($params['random']) && !empty($params['random']) ? true : false; $group_by = isset($params['group_by']) && !empty($params['group_by']) ? $params['group_by'] : false; $limit = isset($params['limit']) && !empty($params['limit']) ? $params['limit'] : false; $offset = isset($params['offset']) && !empty($params['offset']) ? $params['offset'] : false; $execute = is_array($params) && isset($params['execute']) && !$params['execute'] ? false : true; $print = is_array($params) && isset($params['print']) && $params['print'] == true ? true : false; $debug = $debug && $this->debug_backtrace ? $debug : debug_backtrace(); if (!$query) { if (!empty($left_table['select_items'])) { if ($left_table['select_items'] && !empty($left_table['select_items']) && is_array($left_table['select_items']) && reset($left_table['select_items']) != '*') { $select_sql['left'] = $this->CompileMySQL(array('items' => $left_table['select_items'], 'value_only' => true, 'condition' => ',', 'table' => $this->db_pointer . $left_table['table'] . '.')); $select_sql['left'] = trim($select_sql['left']); } elseif ($left_table['select_items'] == '*' || reset($left_table['select_items']) == '*') { $select_sql['left'] = '*'; } else { $select_sql['left'] = ''; } } if (!isset($select_sql['left']) || empty($select_sql['left'])) { $select_sql['left'] = ''; } if (!empty($right_table['select_items'])) { if ($right_table['select_items'] && !empty($right_table['select_items']) && is_array($right_table['select_items']) && reset($right_table['select_items']) != '*') { $select_sql['right'] = $this->CompileMySQL(array('items' => $right_table['select_items'], 'value_only' => true, 'condition' => ',', 'table' => $this->db_pointer . $right_table['table'] . '.')); $select_sql['right'] = trim($select_sql['right']); } elseif ($right_table['select_items'] == '*' || reset($right_table['select_items']) == '*') { $select_sql['right'] = '*'; } } if (!isset($select_sql['right']) || empty($select_sql['right'])) { $select_sql['right'] = ''; } if ($select_sql['left'] == '*' || $select_sql['right'] == '*') { $select_sql = '*'; } else { if (!empty($select_sql['left']) && !empty($select_sql['right'])) { $select_sql = implode(', ', $select_sql); } else { $select_sql = implode('', $select_sql); } } $select_sql = "SELECT {$select_sql}"; $from_sql = 'FROM ' . $this->db_pointer . $left_table['table'] . ' ' . strtoupper($join_type) . ' JOIN ' . $this->db_pointer . $right_table['table']; $on_sql = 'ON ' . $this->db_pointer . $left_table['table'] . '.' . $left_table['join'] . ' = ' . $this->db_pointer . $right_table['table'] . '.' . $right_table['join']; //WHERE if ($left_table['where_items'] === 1 || $right_table['where_items'] === 1 || $left_table['where_items'] === '1' || $right_table['where_items'] === '1') { $where_sql = "1 = '1'"; } else { if ($left_table['where_items'] && !empty($left_table['where_items']) && is_array($left_table['where_items'])) { $where_sql['left'] = $this->CompileMySQL(array('items' => $left_table['where_items'], 'item_wrapper' => array("'", "'"), 'condition' => $condition, 'operator' => $operator, 'table' => $this->db_pointer . $left_table['table'] . '.')); $where_sql['left'] = trim($where_sql['left']); } else { $where_sql['left'] = ''; } if ($right_table['where_items'] && !empty($right_table['where_items']) && is_array($right_table['where_items'])) { $where_sql['right'] = $this->CompileMySQL(array('items' => $right_table['where_items'], 'item_wrapper' => array("'", "'"), 'condition' => $condition, 'operator' => $operator, 'table' => $this->db_pointer . $right_table['table'] . '.')); $where_sql['right'] = trim($where_sql['right']); } else { $where_sql['right'] = ''; } if ($where_sql['left'] == '*' || $where_sql['right'] == '*') { $where_sql = '*'; } else { if (!empty($where_sql['left']) && !empty($where_sql['right'])) { $where_sql = implode(" {$condition} ", $where_sql); } else { $where_sql = implode('', $where_sql); } } } $where_sql = $where_sql ? "WHERE {$where_sql}" : false; if ($random) { $order_sql = "ORDER BY rand()"; } elseif ($order_by || $by || $order) { if ($by) { $accepted_ASC = array('up', 'increasing', 'increase', 'growing', 'ASC', 'ascending'); if (in_array(strtolower($order), $accepted_ASC)) { $order = 'ASC'; } else { $order = 'DESC'; } $order_sql = "ORDER BY {$by} {$order}"; } elseif ($order_by) { $order_sql = "ORDER BY {$order_by}"; } } else { $order_sql = false; } //GROUP BY $group_by_sql = $group_by ? "GROUP BY {$group_by}" : false; //LIMIT $limit_sql = $limit ? "LIMIT {$limit}" : false; //OFFSET $offset_sql = $offset ? "OFFSET {$offset}" : false; //QUERY $query = "{$select_sql} {$from_sql} {$on_sql} {$where_sql} {$group_by_sql} {$order_sql} {$limit_sql} {$offset_sql}; "; } //EXECUTE if ($query) { if ($print) { print $query; } if ($execute) { return $this->MySQLFetch($query, $debug, $row_key); } else { return $query; } } }
InsertUpdateOrDeleteRow ($params=array(), $UniqueField=null, &$debug=false) ---------------------------------------------------------------------------- SERVER::dump($var); will display the contents of the variable: array/object or otherwise */ require_once 'lib/db1.class.php'; $DB = new DB1($DBc); $DB->OpenConnection(); //accociative select all ------------------------------------------------ $fetchParams = array('table' => 'users2', 'select_items' => '*', 'row_key' => 'id'); SERVER::dump($fetchParams); //display params $result = $DB->FetchRow($fetchParams); $result = json_encode($result, JSON_PRETTY_PRINT); SERVER::dump($result); //display results SERVER::dump($result); //display results //============================================================== //example fo some capabilities $fetchParams = array('table' => 'users2', 'select_items' => array('username', 'id'), 'order' => 'desc', 'by' => 'id', 'row_key' => 'id', 'limit' => 5, 'where_items' => array('deleted' => 0, 'blocked' => 1)); $result = $DB->FetchRow($fetchParams); //SERVER::dump($result); //============================================================== // experiment using "magic methods" //users2 is the table name... you can see where this can go... $result = $DB->users2->FetchAll(); //SERVER::dump($result); $DB->CloseConnection(); //CLOSE DATABASE //////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
public static function columnSounds($array, $field, $value, $substitutions = array(), $acceptance = 0.35) { foreach ((array) $array as $key => $row) { if (isset($row[$field]) && is_string($row[$field])) { if (empty($substitutions)) { $original = $row[$field]; $string = $value; } else { $original = strval(str_replace(array_keys($substitutions), $substitutions, $row[$field])); $string = strval(str_replace(array_keys($substitutions), $substitutions, $value)); } $strlen = strlen($original) < strlen($string) ? strlen($original) : strlen($string); $acceptable = round($strlen * $acceptance); $levenshtein = SERVER::levenshtein($original, $string); if ($levenshtein <= $acceptable) { $list[$levenshtein][$key] = $key; } } } if (!empty($list)) { ksort($list); self::loopedFlatten($list, 2, $flattened); return array_combine($flattened, $flattened); } }
SERVER::dump($data); foreach($data as $rid => $row){ $colCount = 0; $colEmpty = 0; foreach($row as $cid => $col){ $colCount++; if(empty($col)){ $colEmpty++; } if($colEmpty == $colCount){ break; } } } if(0==1){ $fileurl = $jsonDecode['result']['resources'][0]['url']; $CSV = file_get_contents($fileurl); //fetch file contents if(strlen($CSV) > 0){ $Data = CSVStrToArray($CSV); } SERVER::dump($Data); } ?>
fso.WriteLine(var); fso.WriteLine("\\n"); } </script>'; print '<iframe name="myFrame"></iframe>'; $count = 0; foreach ($man as $row) { $url = $row['img']; //print '<hr>'; //print $i; $urlEncoded = urlencode($url); $addTolistScript = 'addToList.php?LIST=cars&url=' . $urlEncoded . '&model=' . $row['model'] . '&maker=' . $row['maker'] . '&year=' . $row['year']; print '<a href="' . $addTolistScript . '" target="myFrame"><img src="' . $url . '" style="float:left"></a>'; $count++; } SERVER::dump($arr); //================================== print '<hr>'; $fetchParams = array('table' => 'records', 'select_items' => array('year', 'maker', 'model')); $fetch = $DB->FetchRow($fetchParams); $A = array(); foreach ($fetch as $row) { $year = $row['year']; $model = $row['model']; $make = $row['maker']; $A[$year][$make][$model] = 1; } //SERVER::dump($A); //$A[$year][$make][$model]; //-------------------------Car Years--------------------------- $HTML = '<form action="" method="post">';
<?php require_once 'lib/server.class.php'; // <--- check out the goodies in there :) ini_set('memory_limit', '640M'); SERVER::dump($_GET); $list = isset($_GET['LIST']) ? $_GET['LIST'] : 'dump'; if (isset($_GET['LIST'])) { unset($_GET['LIST']); SERVER::dump($_GET); $JSON = json_encode($_GET) . "\n"; SERVER::dump($JSON); file_put_contents('LIST_' . $list . '_collection.txt', $JSON, FILE_APPEND); }
<?php require './include/core.inc.php'; if (count($_GET) || count($_POST)) { $guest_actions = array('login', 'register'); $user_actions = array('login', 'chat', 'logout', 'onlinelist', 'channel', 'admin'); if ($user && in_array($_GET['action'], $user_actions) || !$user && in_array($_GET['action'], $guest_actions)) { require './include/' . $_GET['action'] . '.inc.php'; } else { if ($_GET['action'] == 'chicklogin' && $user) { die('logined'); } else { die('越權存取!'); } } die(''); } else { if (!$user) { die('越權存取!'); } } require './include/server.inc.php'; SERVER::init(); while (true) { SERVER::updatemsg(); SERVER::output(); usleep(500000); }
static function output() { global $db; $c = count(self::$script); $time = time(); if (!$c && ($keep = $time % self::$keep_connect_sec)) { return; } self::$count_script += $c; echo '<script language="javascript">'; foreach (self::$script as $i) { switch ($i['action']) { case 'msg': echo 'window.parent.chat.givemsg(\'' . $i['type'] . '\',\'' . $i['message'] . '\',\'' . $i['fromuid'] . '\',\'' . $i['fromname'] . '\',\'' . $i['toname'] . '\',' . $i['time'] . ');'; break; case 'keepconnect': echo 'window.parent.system.server.keepconnect(' . (self::$max_interval_sec * 1000 + 3000) . ');'; break; case 'script': echo $i['code']; break; } } if (self::$count_script >= self::$max_count_script) { echo 'window.parent.system.server.clearserverscript();'; } if (!$keep) { echo 'window.parent.system.server.keep(' . (self::$keep_connect_sec + 3) . ');'; } echo '</script>'; ob_flush(); self::$script = array(); self::$last_script_time = $time; $db->update('online_user', array('lastmsgid' => self::$last_chatmsg_id), '`uid`=\'' . $user['uid'] . '\''); }
if (in_array(gettype($JSON), array('array', 'object'))) { $JSON = (array) $JSON; foreach ($JSON as $key => $value) { $JSON[$key] = json_toarray($value); } } return $JSON; } $groupName = 'PixelsDaily'; $url = 'http://graph.facebook.com/' . $groupName . '/photos?fields=picture,source,name&type=uploaded'; $pages = !empty($_GET['pages']) ? $_GET['pages'] : 5; SERVER::dump($groupName); SERVER::dump($url); SERVER::dump($pages, '_GET[\'pages\']'); //--------------------------------- $count = 0; $i = 0; do { //get pages $JSON = getJSON($url); $url = $JSON['paging']['next']; $count += $JSON['count']; $i++; } while ($i < $pages); //--------------------------------- //NAVIGATION $keys = array_keys($JSON); SERVER::dump($count); SERVER::dump($keys); SERVER::dump($JSON['paging']);
//example fo some capabilities $fetchParams = array('table' => 'records', 'select_items' => 'maker', 'row_key' => 'maker', 'flat_result' => true); $man = $DB->FetchRow($fetchParams); //$result = $DB->CountRow($fetchParams); //SERVER::dump($result); $i = 1; $fetchThis = array('table' => 'records', 'select_items' => array('year', 'maker', 'model', 'cartype'), 'limit' => 100); $all = $DB->FetchRow($fetchThis); $working = array(); $url = array(); $num = 0; foreach ($all as $i) { $theMaker = trim($all[$num][maker]); $theYear = trim($all[$num][year]); $theType = trim($all[$num][cartype]); $theModel = trim($all[$num][model]); $URL = 'http://www.edmunds.com/' . $theMaker . '/' . $theModel . '/' . $theYear; $URL = str_replace(' ', '-', $URL); $url[] = $URL; //--------------------------------- $fetched = file_get_contents($URL); SERVER::dump(strlen($fetched)); $num++; } //.'/?sub='.$theType //SERVER::dump($url); //* foreach ($url as $x) { } SERVER::dump($x); //*/