Uutiset:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu
Advertisement:

Can't seem to get $smcFunc['db_create_table'] to work

Aloittaja Randem, joulukuu 22, 2013, 12:06:00 AP

« edellinen - seuraava »

Randem

I am having issues with this function. I followed the online manual instruction exactly but this is the error message that I get and it is quite vague. Line 126 is the $smcFunc['db_create_table'] line. What could possibly be incorrect. Also is there any flag that can be set so that when smcFunc throws an error that the generated SQL is returned for inspection. It would help a lot to see what is actually being generated.

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/57/10005557/html/smftest/Sources/TopicVisitsLog.php on line 126



db_extend('packages');

$columns = array(
array(
'name' => 'id_no',
'type' => 'int',
'size' => 10,
'unsigned' => true,
'null' => false,
'auto' => true,
),
array(
'name' => 'id_board',
'type' => 'smallint',
'size' => 5,
'unsigned' => true,
'null' => false,
'default' => 0,
),
array(
'name' => 'id_topic',
'type' => 'int',
'size' => 10,
'unsigned' => true,
'null' => false,
'default' => 0,
),
array(
'name' => 'id_member',
'type' => 'mediumint',
'size' => 8,
'unsigned' => true,
'null' => false,
'default' => 0,
),
array(
'name' => 'ip_addr',
'type' => 'char',
'size' => 16,
'null' => false,
),
array(
'name' => 'rpt_date',
'type' => 'date',
'null' => false,
),
array(
'name' => 'updated',
'type' => 'timestamp',
'null' => false,
),
);

$indexes = array(
array(
'type' => 'primary',
'columns' => array('id_no'),
),
array(
'type' => 'unique',
'columns' => array('id_board','id_topic','ip_addr','rpt_date'),
),
);


$result = $smcFunc['db_create_table']('log_topic_stats', $columns, $indexes, array(), 'ignore');
BotBanish - The Ultimate Bot Firewall
Scams - How to Protect Yourself
Why Professionals Should Not Use Free Email Accounts

Always ignore those who attempt to tell you what to think and believe those who will allow you think for yourself

emanuele

Are you sure you didn't forget a comma in your code that you added here?

Another thing, I think you want to do:
$result = $smcFunc['db_create_table']('{db_prefix}log_topic_stats', $columns, $indexes, array(), 'ignore');

Don't you want to add the prefix to the table name?

ETA: that may help too http://wiki.simplemachines.org/smf/$smcFunc


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

Randem

What missing comma? Where? The code you show is exactly the same as my original.

BTW: I tried with prefix and without prefix but no joy. The documentation is contradicting on that point. Some of it says to add the prefix and some of it says not to for the same function... Some of the documentation states that there are five parameters to the call ad others state 6. The actual code does not use the 6th parameter. I have tried it with 5 and 6 parameters and no matter what change I make to the line the error is always the same... It's a parsing error so I would imagine that this function has a prototype somewhere?
BotBanish - The Ultimate Bot Firewall
Scams - How to Protect Yourself
Why Professionals Should Not Use Free Email Accounts

Always ignore those who attempt to tell you what to think and believe those who will allow you think for yourself

Randem

I did some research and found the the error was not on that line at all. The error was in the script beyond that line but the error message kept stating that line was the error. Trial & Error by commenting out other parts of the script until I got a different error.  Still no table creation but getting closer... :-\
BotBanish - The Ultimate Bot Firewall
Scams - How to Protect Yourself
Why Professionals Should Not Use Free Email Accounts

Always ignore those who attempt to tell you what to think and believe those who will allow you think for yourself

Randem

Ok, got it working after tracking down that the error was not where it was reported...
BotBanish - The Ultimate Bot Firewall
Scams - How to Protect Yourself
Why Professionals Should Not Use Free Email Accounts

Always ignore those who attempt to tell you what to think and believe those who will allow you think for yourself

emanuele

Lainaus käyttäjältä: Randem - joulukuu 22, 2013, 04:06:15 IP
BTW: I tried with prefix and without prefix but no joy. The documentation is contradicting on that point. Some of it says to add the prefix and some of it says not to for the same function... Some of the documentation states that there are five parameters to the call ad others state 6.
Where did you see the discrepancy?
I'm rather sure of what I wrote in the online manual (the link I posted before), for the rest I don't know.

Lainaus käyttäjältä: Randem - joulukuu 22, 2013, 04:06:15 IP
The actual code does not use the 6th parameter.
The fact that a function has 6 parameters doesn't mean they are all mandatory, some may be optional. In that particular case, there are 3 parameters that are mandatory, the others can be omitted.

Lainaus käyttäjältä: Randem - joulukuu 22, 2013, 04:06:15 IP
I have tried it with 5 and 6 parameters and no matter what change I make to the line the error is always the same... It's a parsing error so I would imagine that this function has a prototype somewhere?
Well, as you discovered later syntax errors are usually not related to wrong number of parameters, at maximum a missing argument can trigger a warning, but not a syntax error. ;)


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

Advertisement: