There are two good ways in which we can counter this:
We can use a conditional SQL query when the module is invoked. A
consideration, if using this method, is the additional strain that is placed
on the database server, especially if you are creating multiple tables. The
following example demonstrates how we can achieve this:
$db =& JFactory::getDBO();
$query = 'CREATE TABLE IF NOT EXISTS '.$db-
>nameQuote('#__some_table').' ( '.$db-
>nameQuote('id').' int(11) NOT NULL auto_increment, '
.$db->nameQuote('name').' varchar(255) NOT NULL default '', '
.'PRIMARY KEY ('.$db->nameQuote('id'). ') '
.') CHARACTER SET `utf8` COLLATE `utf8_general_ci`';
$db->setQuery($query);
$db->query();
We can use a flag to indicate if the tables have already been created. We can
implement a flag in several ways. For example, we could use a blank file or
a module configuration option. This example demonstrates how we can use
a module configuration option (we will discuss the module configuration
options in the next section):
if (!$params->get('tablecreated'))
{
// create the table
$db =& JFactory::getDBO();
$query = 'CREATE TABLE IF NOT EXISTS '.
Pages:
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170