· 8 years ago · Jun 30, 2018, 06:18 AM
1<?php
2// $Id$
3
4//menus-
5
6//create a menu item and assign it to primary links using code
7
8function dbres_menu() {
9
10$items['dbres/newyear'] = array(
11'title' => 'Task',
12'page callback' => 'dbres_newyear',
13'access callback' => TRUE,
14'type' => MENU_NORMAL_ITEM,
15);
16
17$items['dbresults/test'] = array(
18'title' => 'Task5',
19'page callback' => 'dbres_display',
20'access callback' => TRUE,
21'type' => MENU_NORMAL_ITEM,
22);
23
24return $items;
25}
26
27
28function dbres_newyear() {
29 return t('Wish you a happy new year');
30}
31
32function dbres_display() {
33
34// Implementing db_table_exists
35
36if (db_table_exists('role')) {
37 $page_content = 'Table Role exists. Look below for other query results.'.'<br>'.'<br>';
38}
39else {
40 $page_content = 'Table Example does not exist.';
41 return $page_content;
42}
43
44// Implementing db_query
45
46$result = db_query('SELECT * FROM {node}');
47
48
49//Paging the database
50$pager_num = 0; // This is the first pager on this page. number is 0.
51
52// Implementing db_rewrite_sql
53//$result = pager_query(db_rewrite_sql($sql), 10, $pager_num, NULL, $type,$status);
54
55// Implementing db_fetch_object
56
57while ($data = db_fetch_object($result)) {
58 $node = node_load($data->nid);
59 $result = db_query('SELECT name FROM {users} where uid= %d', $node->uid);
60 $result1 = db_query('SELECT body FROM {node_revisions} where nid= %d', $node->nid);
61 $page_content = ('Name of creator = '.db_result($result));
62 $page_content .= '<br>'.'Title = '.$node->type;
63 $page_content .= '<br>'.'Description = '.db_result($result1);
64}
65
66//Implementing db_version
67$page_content .= '<br>version of the database = '.db_version();
68
69//Implementing db_column_exists
70if (db_column_exists('nodes', 'type')) {
71$page_content .= '<br>Type column exists in node table';
72}
73
74else {
75$page_content .= '<br>Error! Check your node table implementation';
76}
77
78return $page_content;
79}