Sql_Error

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
Aaron_H

Sql_Error

Post 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
User avatar
duclet
Forum Members
Forum Members
Posts: 187
Joined: Fri Jun 23, 2006 12:55 pm

Re: Sql_Error

Post 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.
NaN

Re: Sql_Error

Post 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.
Post Reply

Return to “Developers Discussion”