Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

sqlquery.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: sqlquery.php 7785 2001-10-11 11:39:51Z bf $
5 //
6 // Created on: <26-Sep-2001 19:23:56 bf>
7 //
8 // This source file is part of Exponential Basic, publishing software.
9 //
10 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
11 //
12 // This program is free software; you can redistribute it and/or
13 // modify it under the terms of the GNU General Public License
14 // as published by the Free Software Foundation; either version 2
15 // of the License, or (at your option) any later version.
16 //
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
25 //
26
27 // TODO
28 //
29 // after testing it a bit; here is the features I think we should implement:
30 //+ display number of rows in result
31 //- use template on the table code
32 //+ use intl strings on the error messages
33 //+ save queries, mabye save it in the user preferences ( use the
34 // eZPrefrerences class )
35 //- Be able to reuse saved queries ( for quicker handling of multiple queries,
36 // mabye a drop down selection of your saved queries )
37 //- export the result to a comma separated file to open in excel etc.
38 //- show errors in a friendly way ( both mysql and postgresql ) not a high pri.
39 //
40
41 // include_once( "classes/ezdb.php" );
42
43 $Language = $ini->variable( "eZSiteManagerMain", "Language" );
44
45 $t = new eZTemplate( "kernel/ezsitemanager/admin/" . $ini->variable( "eZSiteManagerMain", "AdminTemplateDir" ),
46 "kernel/ezsitemanager/admin/intl", $Language, "sqlquery.php" );
47
48 $t->set_file( "sql_query_tpl", "sqlquery.tpl" );
49
50 $t->setAllStrings();
51
52
53 // include the code
54 // include_once( "ezsession/classes/ezpreferences.php" );
55 $preferences = new eZPreferences();
56
57 // get the preferences
58 $QueryPref =& $preferences->variableArray( "QueryPref" );
59
60 if ( isset( $Run2 ) )
61 {
62 $QueryText = $QueryText2;
63 }
64
65 if ( $QueryPref )
66 {
67 $QueryText2 = "<select name=\"QueryText2\">";
68
69 foreach ( $QueryPref as $key => $val )
70 {
71 $QueryText2 .= "<option>$val</option>";
72 }
73
74 $QueryText2 .= "</select>";
75
76 }
77
78
79 $db =& eZDB::globalDatabase();
80
81 $QueryRes = '';
82 $QueryError = '';
83
84 if ( !isset( $QueryText ) )
85 {
86 $QueryError = 'No query specified';
87 }
88 else
89 {
90 $QueryText = trim( $QueryText );
91 $QueryArray = explode( " ", $QueryText );
92
93 if ( $QueryArray[0] == "insert" ||
94 $QueryArray[0] == "update" ||
95 $QueryArray[0] == "create" ||
96 $QueryArray[0] == "alter" )
97 {
98 $db->query( $QueryText );
99 }
100 else
101 {
102 $db->array_query( $return_array, $QueryText );
103 }
104
105 if ( $return_array )
106 {
107 $QueryRes .= "<table width=\"100%\" border=\"1\" >";
108
109 $QueryRes .= "<tr>";
110
111 // print the column names
112 reset( $return_array[0] );
113 foreach ( $return_array[0] as $key => $val )
114 {
115 foreach ( $return_array[0] as $key => $res )
116 {
117 if( !is_integer( $key ) )
118 {
119 $QueryRes .= "<th>" . $key . "</th>";
120 }
121 }
122 }
123
124 $QueryRes .= "</tr>";
125
126 for ( $i = 0; $i < count( $return_array ); $i++ )
127 {
128
129 $QueryRes .= "<tr>";
130
131 for ( $j = 0; $j < count( $return_array[$i]) / 2 ; $j++ )
132 {
133 if( !is_null( $return_array[$i][$j] ) )
134 $QueryRes .= "<td>" . htmlspecialchars( $return_array[$i][$j] ) . "</td>";
135 }
136 $QueryRes .= "</tr>";
137 }
138 $QueryRes .= "</table>";
139
140
141 // set the preferences
142
143 if ($QueryText <> $QueryPref[count ($QueryPref) - 1 ] )
144 {
145 $QueryPref = array_merge ( $QueryPref, array ( $QueryText) );
146 $preferences->setVariable( "QueryPref", $QueryPref );
147 }
148 else
149 {
150 $preferences->setVariable( "QueryPref", $QueryPref );
151 }
152
153 }
154 else
155 {
156 $QueryError = "SQL error occured";
157 }
158
159
160
161 }
162
163 if( isset( $QueryText ) )
164 {
165
166 $t->set_var( "query_text", $QueryText );
167 }
168 else
169 {
170
171 $t->set_var( "query_text", '' );
172 }
173
174 if( isset( $QueryText2 ) )
175 {
176 $t->set_var( "query_text2", $QueryText2 );
177 }
178 else
179 {
180 $t->set_var( "query_text2", '' );
181 }
182
183 if( isset( $return_array ) )
184 {
185 $t->set_var( "query_rows", count ($return_array));
186 }
187 else
188 {
189 $t->set_var( "query_rows", 0 );
190 }
191
192
193 $t->set_var( "query_result", $QueryRes );
194
195 if( isset( $return_array ) )
196 {
197 $t->set_var( "query_rows", count ($return_array));
198 }
199 else
200 {
201 $t->set_var( "query_rows", 0 );
202 }
203
204 $t->set_var( "error", $QueryError );
205
206 $t->pparse( "output", "sql_query_tpl" );
207
208 ?>
$i
$i
Definition: admin/adlist.php:91
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZPreferences
Definition: ezpreferences.php:62
eZTemplate
Definition: eztemplate.php:107
$ini
$ini
Definition: classes/admin/linklist.php:64
$j
$j
Definition: ezimagecatalogue/admin/imagelist.php:345
$res
$res
Definition: ezstats/admin/cron.php:45
$QueryError
$QueryError
Definition: sqlquery.php:82
$QueryArray
$QueryArray
Definition: sqlquery.php:91
$t
$t
Definition: sqlquery.php:45
$QueryPref
$QueryPref
Definition: sqlquery.php:58
$QueryRes
$QueryRes
Definition: sqlquery.php:81
$preferences
$preferences
Definition: sqlquery.php:55
$Language
$Language
Definition: sqlquery.php:43
$db
if(isset( $Run2)) if( $QueryPref) $db
Definition: sqlquery.php:79
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.