I did notice something rather redundant and possibly a painful issue when developing. Your tables are declared in the pntables.php and created and dropped in pninit.php. However the code between the two files can become difficult to maintain. Your modules database schema is in 3 or more places(Modulename_pntables, Modulename_init, Modulename_delete) if you use the example module given.
I got around this by creating a function in pntables.php that returns a multidimensional array that has the table name as key then an array of fields which are arrays name, type, length, autoincrement, primary key,
Code
function Modulename_pntableinfo()
{
$columns[]=array('name'=>'id','auto'=>1,'primary'=>1,'type'=>'bigint','length'=>20); $columns[]=array('name'=>'name','type'=>'varchar','length'=>20);
$tables['tablename1']=$columns;
$columns[]=array('name'=>'id','auto'=>1,'primary'=>1,'type'=>'bigint','length'=>20);
$columns[]=array('name'=>'name','type'=>'varchar','length'=>20);
$tables['tablename2']=$columns;
return $tables;
}
{
$columns[]=array('name'=>'id','auto'=>1,'primary'=>1,'type'=>'bigint','length'=>20); $columns[]=array('name'=>'name','type'=>'varchar','length'=>20);
$tables['tablename1']=$columns;
$columns[]=array('name'=>'id','auto'=>1,'primary'=>1,'type'=>'bigint','length'=>20);
$columns[]=array('name'=>'name','type'=>'varchar','length'=>20);
$tables['tablename2']=$columns;
return $tables;
}
Then Modulename_pntables reads this array and adds pnConfigGetVar('prefix') and the module name and returns valid a pntable array for the rest of the system.
My init and deletet functions for the use the results of the above function to create and delete the tables.
The benefit is that you can modify your table structure in 1 place instead of 3.
It doesn't support Modulename_update though. (maybe add a version item in the field array?)
Does anyone know of a better way than the example or what I've written?
Thanks!
Leigh
