$data["weight"] = sqrt($row); $data["access_date"] = MetabaseToday(); $data["access_time"] = MetabaseTime(); $data["approved"] = MetabaseNow(); if ($prepared_query = MetabasePrepareQuery($database, "INSERT INTO users (user_name,user_password,subscribed,user_id,quota,weight,access_date,access_time,approved) VALUES (?,?,?,?,?,?,?,?,?)")) { if (!InsertTestValues($database, $prepared_query, $data)) { $success = 0; } MetabaseFreePreparedQuery($database, $prepared_query); if ($success) { if (!($result = MetabaseQuery($database, "SELECT user_name,user_password,subscribed,user_id,quota,weight,access_date,access_time,approved FROM users"))) { $success = 0; } else { $fields = array("user_name", "user_password", "subscribed", "user_id", "quota", "weight", "access_date", "access_time", "approved"); if (($columns = MetabaseNumberOfColumns($database, $result)) == count($fields)) { if ($success = MetabaseGetColumnNames($database, $result, $column_names)) { if ($columns == count($column_names)) { for ($column = 0; $column < $columns; $column++) { if ($column_names[$fields[$column]] != $column) { $pass = 0; echo "FAILED!{$eol}"; $failed++; echo "Test {$test}: the query result column \"" . $fields[$column] . "\" was returned in position " . $column_names[$fields[$column]] . " unlike {$column} as expected{$eol}"; } } } else { $pass = 0; echo "FAILED!{$eol}"; $failed++; echo "Test {$test}: the query result returned a number of " . count($column_names) . " column names unlike {$columns} as expected{$eol}"; }
/** * Returns only the associative entries of a result * * @abstract * @access private * * @param Array $array * * @return Array */ function _getAssociativeEntries($array) { MetabaseGetColumnNames($this->db, $this->result, $cols); $res = array(); $cols = array_keys($cols); $i = 0; foreach ($array as $value) { $res[$cols[$i++]] = $value; } return $res; }
function getPageRecord($obj) { global $mdb; $join_field = ""; $search_field = ""; $group_by_field = ""; $sort_field = ""; $field = $this->getSelectPageField($obj); $group_by_field = $this->getGroupByField($obj); $sort_field = $this->getSortField($obj); $search_field = $this->getSearchField($obj); $join_field = $this->getJoinField($obj); if (isset($obj->configure["select"]["database_name"])) { if ($obj->configure["select"]["database_name"] != "") { $database_name = "`" . $obj->configure["select"]["database_name"] . "`."; } } $prefix = $obj->config->default_prefix; $prefix_where = "`" . $obj->configure["select"]["table_as_name"] . "`.`prefixid` = '" . $obj->config->default_prefix_id . "'"; if (isset($obj->configure["prefix"])) { if ($obj->configure["prefix"] == 'N') { $prefix = ""; $prefix_where = " 1=1 "; } } if ($group_by_field != "") { $row_field = " count( DISTINCT " . $group_by_field . ") as num"; } else { $row_field = " count(*) as num"; } $query = "SELECT " . $field . " FROM " . $database_name . "`" . $prefix . $obj->configure["select"]["table_name"] . "` AS `" . $obj->configure["select"]["table_as_name"] . "`"; $query_num = "SELECT " . $row_field . " FROM " . $database_name . "`" . $prefix . $obj->configure["select"]["table_name"] . "` AS `" . $obj->configure["select"]["table_as_name"] . "`"; if (!isset($obj->configure["select"]["max_page"])) { $obj->configure["select"]["max_page"] = $obj->config->max_page; } if (!isset($obj->configure["select"]["max_range"])) { $obj->configure["select"]["max_range"] = $obj->config->max_range; } if (is_array($join_field)) { foreach ($join_field as $jfk => $jfv) { $query .= "\n" . $jfv; $query_num .= "\n" . $jfv; } } $query .= "\nWHERE " . $prefix_where; $query_num .= "\nWHERE " . $prefix_where; if ($search_field != '') { $query .= " " . $search_field; $query_num .= " " . $search_field; } if ($group_by_field != '') { $query .= "\nGROUP BY " . $group_by_field; } if ($sort_field != '') { $query .= "\nORDER BY " . $sort_field; } if (isset($obj->configure["dev"])) { if ($obj->configure["dev"] == 'Y') { echo "<pre>"; echo $query_num; echo "<br>"; echo "<br>"; echo $query; exit; } } $rows = $this->getPageRows($query_num, $obj); $page = $this->recordPage($rows, $obj); //echo "<pre>"; print_r($page); exit ; $query_limit = " limit " . ($page["rec_start"] - 1) . "," . $obj->configure["select"]["max_page"]; $query .= $query_limit; //echo "<pre>";print_r($this->getQueryRecord($query,$obj)); exit ; $arr = ""; $this->queryAssign('getPageRecord', $query); $db_res = $this->query($query, $obj); $rows = @MetabaseNumberOfRows($mdb, $db_res); @MetabaseGetColumnNames($mdb, $db_res, $db_field_name); if ($rows) { $sno = $page["rec_start"] - 1; $gno = array(); $sgno = 0; for ($row = 0; $row < $rows; $row++) { if (is_array($db_field_name)) { $sno++; foreach ($db_field_name as $key => $value) { $arr["record"][$row]["no"] = $row; $arr["record"][$row]["sno"] = $sno; $arr["record"][$row][$key] = @MetabaseFetchResult($mdb, $db_res, $row, $key); } } } } $result["table"] = $arr; $result["page"] = $page; return $result; }