SMF Support > SMF 2.0.x Support

error while creating table

(1/2) > >>

System32Cro:
Hi guys,
I've got this error when I try to create table:

--- Code: ---Fatal error: Function name must be a string in C:\xampp\htdocs\smf\Sources\Load.php(2151) : eval()'d code on line 696
--- End code ---

I already checked lines and everything looks good, I didn't modified Load.php


Code of creating table:


--- Code: ---$columns = array(
array(
'name' => 'id_theme',
'type' => 'int',
'size' => 11,
'auto' => true,
),
array(
'name' => 'background',
'type' => 'text',
),
);
$indexes = array(
array(
'type' => 'primary',
'columns' => array('id_theme'),
),
);
$smcFunc['db_create_table']('{db_prefix}lgfPanel', $columns, $indexes, array(), 'ignore');
--- End code ---

Arantor:
The error isn't in Load.php as that error actually tells you. The code is being called from Load.php but it's line 696 of whatever's called from Load.php, which is almost always in the template... are you calling it from a template?!?!

Anyway, your core problem is that before calling $smcFunc, you're not pulling it into scope with global.

System32Cro:

--- Quote from: Arantor on July 24, 2012, 01:16:43 PM ---The error isn't in Load.php as that error actually tells you. The code is being called from Load.php but it's line 696 of whatever's called from Load.php, which is almost always in the template... are you calling it from a template?!?!

Anyway, your core problem is that before calling $smcFunc, you're not pulling it into scope with global.

--- End quote ---
without pulling it into scope it should throw error

--- Code: ---function show_lgfPanel()
{
global $context, $settings, $txt, $smcFunc;

//Show only to forum admins
if($context['user']['is_admin'])
{
$smcFunc['db_query']('', "
CREATE TABLE IF NOT EXISTS {db_prefix}lgfPanel (
`theme_id` int(11) NOT NULL AUTO_INCREMENT,
`background` text NOT NULL,
`font_color` text NOT NULL,
`font` text NOT NULL,
`banners` text NOT NULL,
PRIMARY KEY (`theme_id`)
)
");
/*$columns = array(
array(
'name' => 'id_theme',
'type' => 'int',
'size' => 11,
'auto' => true,
),
array(
'name' => 'background',
'type' => 'text',
),
);
$indexes = array(
array(
'type' => 'primary',
'columns' => array('id_theme'),
),
);
$smcFunc['db_create_table']('{db_prefix}lgfPanel', $columns, $indexes, array(), 'ignore');*/

$result = $smcFunc['db_query']('', "SELECT * FROM {db_prefix}lgfPanel WHERE theme_id = ".$settings['theme_id']."");
if($smcFunc['db_num_rows']($result) == 0) $smcFunc['db_query']('', "INSERT INTO {db_prefix}lgfPanel VALUES(".$settings['theme_id'].", '', '', '', '')");

//code...
}
--- End code ---

Arantor:

--- Quote ---without pulling it into scope it should throw error
--- End quote ---

Without pulling into scope it DID throw an error. The error that would be thrown if out of scope would be that the function name must be a string - not in scope would make $smcFunc['db_*'] undefined and thus not a string.


On top of that, db_create_table doesn't work unless db_extend('packages') has been called, and I do not understand why this is being done outside the package manager - if you have to create tables, do it during mod installation, not hard wiring it like that.

There are other aspects to this as well that you're not taking into account, like the db changes log.

System32Cro:
thank you Arantor, works fine now!

Navigation

[0] Message Index

[#] Next page

Go to full version