Page 1 of 1
Sql_Error
Posted: Tue Sep 23, 2008 2:47 pm
by Aaron_H
When creating a install script, for some reason it will not create the table in the database:
$sqlarray = $dict->CreateTableSQL(cms_db_prefix()."module_class_homework",$flds, $taboptarray);
I tried using mysql_error();
this showed no errors.
Any help greatful.
Thanks
Re: Sql_Error
Posted: Tue Sep 23, 2008 4:50 pm
by duclet
What is the contents of $flds and $taboptarray? Also, you might want to take a look at the SQL that is generated to make sure it looks correctly.
Re: Sql_Error
Posted: Tue Sep 23, 2008 4:59 pm
by NaN
Try this one instead (copy of method.install.php of just any existing module that needs some tables):
Code: Select all
// Get a reference to the CMS ADOConnection object
$db =& $this->cms->GetDb();
// Create a ADOdb DataDictionary
$dict =& NewDataDictionary($db);
// DataDictionary typecode for datetime
// (optional) just if you plan to use fields of type date
$datetime = $gCms->config['use_adodb_lite'] ? 'DT' : 'T';
// Create the entry table
// enter your fields here
// you must specify what kind of data it will contain
// e.g. I = integer, C = characters, X = text
// you can limit the size of fields content with numbers within brackets behind the data type
// e.g. ne_field C(255)
// you can also specify if the default value (when nothing is inserted) is NULL or NOTNULL
// (NULL means something like "nothing")
$flds = 'id I KEY,
one_field C(255) NOTNULL,
another_field X NOTNULL';
// etc.
$taboptarray = array('mysql' => 'TYPE=MyISAM');
$sqlarray = $dict->CreateTableSQL(cms_db_prefix() . 'module_guestbook', $flds, $taboptarray);
$dict->ExecuteSQLArray($sqlarray);
This should work.
Don't forget to remove the tables when uninstalling your module.