Uutiset:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu
Advertisement:

Missing argument 5 for smf_db_insert()

Aloittaja The Wizard, helmikuu 02, 2014, 06:03:03 IP

« edellinen - seuraava »

The Wizard

Hello:

I got the following two errors in the error log when I installed [WIP] toy shop.

Line: 592 - 2: Missing argument 5 for smf_db_insert(), called in install.php on line 356 and defined
Line: 592 - 2: Missing argument 5 for smf_db_insert(), called in install.php on line 575 and defined

I'm guessing it wants me to add another value or two, but what to add I'm not sure. I was thinking - 'default' => '1',

Help Please

Wiz


// Insert Shop Categories

$smcFunc['db_insert']('insert', '{db_prefix}shop_categories', array(
'name' => 'string',
'id' => 'int',
'count' => 'int'
),

// Values
array(
'name' => 'The Doctors',
'id' => '500',
'count' => '11'
));




Full install.php Code

<?php

// =============================================================================
// install.php
//
// Toy Shop MOD for Simple Machines Forum
// =============================================================================
//
// Toy Shop by: The Wizard (http://www.wizardsplanet.com)
// Version Number: V 2.0
// Copyright 2013 by: The Wizard
//
// License:
// This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
//
// You are free:
//
//  to Share — to copy, distribute and transmit the work
//  to Remix — to adapt the work 
//
// You may not use this SMF modification except in compliance with
// the License. You may obtain a copy of the License at
// http://creativecommons.org/licenses/by-nc-sa/3.0/
//
// =============================================================================
// Toy Shop was created from SMF Shop
//
// SMF Shop was created by: DanSoft Australia http://www.dansoftaustralia.net/
// Copyright 2005-2007
//
// Software Updated by: vbgamer45 http://www.smfhacks.com
// Copyright 2009-2013
//
// A special thanks goes out to daniel15, and vbgamer45
// for allowing me to use some of the SMF Shop code.
//
// The Wizard
//
// =============================================================================
// Doctor Who, Tardis, and related Doctor Who symbols/images are registered
// trademarks and/or copyrights of BBC and their respective owners.
//
// The Doctor Who aspect of wizards shop is a fan based work, and not intended
// for any commercial application. 
//
// ==============================================================================

if (file_exists(dirname(__FILE__) . '/SSI.php') && !defined('SMF'))
require_once(dirname(__FILE__) . '/SSI.php');
elseif (!
defined('SMF'))
die('<b>Error:</b> Cannot install - please verify that you put this file in the same place as SMF\'s index.php and SSI.php files.');


global 
$smcFunc$db_prefix;

// New settings for the toy shop mod
$newSettings = array(
'shopVersion' => '3.0',
'shopDate' => '23th November 2009',
'shopBuild' => '15',
'shopCurrencyPrefix' => '',
'shopCurrencySuffix' => ' credits',
'shopPointsPerTopic' => '10',
'shopPointsPerPost' => '8',
'shopInterest' => '2',
'shopBankEnabled' => '1',
'shopImageWidth' => '100',
'shopImageHeight' => '100',
'shopTradeEnabled' => '1',
'shopItemsPerPage' => '12',
'shopMinDeposit' => '0',
'shopMinWithdraw' => '0',
'shopRegAmount' => '0',
'shopPointsPerWord' => '0',
'shopPointsPerChar' => '0',
'shopPointsLimit' => '0',
'shopFeeWithdraw' => '0',
'shopFeeDeposit' => '0',
'NumberOfShopItemsToDisplay' => '15',
'ToyShopPortrait' => 'The Doctor',
);

// Insert into the database
foreach ($newSettings as $variable => $value)
{
$smcFunc['db_insert']('replace''{db_prefix}settings',
array(
'variable' => 'string',
'value' => 'string',
),
array(
'variable' => $variable,
'value' => $value,
),
array()
);
}

// Add a column for money
$smcFunc['db_add_column']('{db_prefix}members', array(
'name' => 'money',
'type' => 'decimal',
'default' => '100.00',
));

// Add a column for banked money
$smcFunc['db_add_column']('{db_prefix}members', array(
'name' => 'moneyBank',
'type' => 'decimal',
'default' => '0.00',
));


// Modify Boards
$smcFunc['db_add_column']('{db_prefix}boards', array(
'name' => 'countMoney',
'type' => 'tinyint',
'size' => 1,
'default' => '1',
));


$smcFunc['db_add_column']('{db_prefix}boards', array(
'name' => 'shop_pertopic',
'type' => 'decimal',
'size' => '9,2',
'default' => '0.00',
));


$smcFunc['db_add_column']('{db_prefix}boards', array(
'name' => 'shop_perpost',
'type' => 'decimal',
'size' => '9,2',
'default' => '0.00',
));


$smcFunc['db_add_column']('{db_prefix}boards', array(
'name' => 'shop_bonuses',
'type' => 'tinyint',
'size' => 1,
'default' => '1',
));


// Item table
$smcFunc['db_create_table']('{db_prefix}shop_items',
array(
array(
'name' => 'id',
'type' => 'int',
'size' => 10,
'auto' => true,
),
array(
'name' => 'name',
'type' => 'varchar',
'size' => 50,
),
array(
'name' => 'desc',
'type' => 'text',
),
array(
'name' => 'price',
'type' => 'decimal',
'size' => '8,2',
'default' => '0.00',
),
array(
'name' => 'module',
'type' => 'tinytext',
),
array(
'name' => 'stock',
'type' => 'smallint',
'size' => 6,
),
array(
'name' => 'info1',
'type' => 'text',
'null' => true,
),
array(
'name' => 'info2',
'type' => 'text',
'null' => true,
),
array(
'name' => 'info3',
'type' => 'text',
'null' => true,
),
array(
'name' => 'info4',
'type' => 'text',
'null' => true,
),
array(
'name' => 'input_needed',
'type' => 'tinyint',
'size' => 1,
'default' => 0,
),
array(
'name' => 'can_use_item',
'type' => 'tinyint',
'size' => 1,
'default' => 0,
),
array(
'name' => 'delete_after_use',
'type' => 'tinyint',
'size' => 1,
'default' => 0,
),
array(
'name' => 'image',
'type' => 'tinytext',
'null' => true,
),
array(
'name' => 'category',
'type' => 'smallint',
'size' => 6,
'default' => 0,
),
),
array(
array(
'name' => 'id',
'type' => 'primary',
'columns' => array('id'),
),
),
array(),
'overwrite');

// Inventory table
$smcFunc['db_create_table']('{db_prefix}shop_inventory',
array(
array(
'name' => 'id',
'type' => 'int',
'size' => 10,
'auto' => true,
),
array(
'name' => 'ownerid',
'type' => 'int',
'size' => 10,
),
array(
'name' => 'itemid',
'type' => 'int',
'size' => 10,
),
array(
'name' => 'amtpaid',
'type' => 'decimal',
'size' => '8,2',
'default' => '0.00',
),
array(
'name' => 'trading',
'type' => 'tinyint',
'size' => 1,
),
array(
'name' => 'tradecost',
'type' => 'decimal',
'size' => '8,2',
'default' => '0.00',
),
),
array(
array(
'name' => 'id',
'type' => 'primary',
'columns' => array('id'),
),
),
array(),
'overwrite');

// Category table
$smcFunc['db_create_table']('{db_prefix}shop_categories',
array(
array(
'name' => 'id',
'type' => 'smallint',
'size' => 5,
'auto' => true,
),
array(
'name' => 'name',
'type' => 'varchar',
'size' => 50,
),
array(
'name' => 'count',
'type' => 'int',
'size' => 10,
),
),
array(
array(
'name' => 'id',
'type' => 'primary',
'columns' => array('id'),
),
),
array(),
'overwrite');

// Create a Column called wizard

global $smcFunc;

if (!
array_key_exists('db_add_column'$smcFunc))
db_extend('packages');

$column_array = array(
'column1' => array(
'name' => 'wizard',
'type' => 'varchar',
'size' => '800',
'null' => false,
'default' => ''
)
);

foreach (
$column_array as $key => $data)
{
$smcFunc['db_add_column']('{db_prefix}members'$data, array(), 'update''fatal');
}

// ***** Doctor Who Item Package *****

global $smcFunc;

// Insert Shop Categories 

$smcFunc['db_insert']('insert''{db_prefix}shop_categories', array(
'name' => 'string',
'id' => 'int',
'count' => 'int'
), 

// Values
array(
'name' => 'The Doctors',
'id' => '500',
'count' => '11'
));

// Insert shop items
$smcFunc['db_insert']('insert''{db_prefix}shop_items'

// Fields
array(
'name' => 'string',
'desc' => 'string',
'price' => 'float',
'module' => 'string',
'stock' => 'int',
'image' => 'string',
'info1' => 'int',
'info2' => 'int',
'input_needed' => 'int',
'can_use_item' => 'int',
'delete_after_use' => 'int',
'category' => 'int'
), 

// Values
array(

// 1. - 1st Doctor
array(
'name' => '01st Doctor',
'desc' => 'Doctor Who',
'price' => 50.00,
'module' => 'Doctor01',
'stock' => 50,
'image' => 'doctor01.png',
'info1' => 0,
'info2' => 0,
'input_needed' => 1,
'can_use_item' => 1,
'delete_after_use' => 1,
'category' => 500
),

// 2. - 2nd Doctor
array(
'name' => '02nd Doctor',
'desc' => 'Doctor Who',
'price' => 50.00,
'module' => 'Doctor02',
'stock' => 50,
'image' => 'doctor02.png',
'info1' => 0,
'info2' => 0,
'input_needed' => 1,
'can_use_item' => 1,
'delete_after_use' => 1,
'category' => 500
),

// 3. - 3rd Doctor
array(
'name' => '03rd Doctor',
'desc' => 'Doctor Who',
'price' => 50.00,
'module' => 'doctor03',
'stock' => 50,
'image' => 'doctor03.png',
'info1' => 0,
'info2' => 0,
'input_needed' => 1,
'can_use_item' => 1,
'delete_after_use' => 1,
'category' => 500
),

// 4. - 4th Doctor
array(
'name' => '04th Doctor',
'desc' => 'Doctor Who',
'price' => 50.00,
'module' => 'doctor04',
'stock' => 50,
'image' => 'doctor04.png',
'info1' => 0,
'info2' => 0,
'input_needed' => 1,
'can_use_item' => 1,
'delete_after_use' => 1,
'category' => 500
),

// 5. - 5th Doctor
array(
'name' => '05th Doctor',
'desc' => 'Doctor Who',
'price' => 50.00,
'module' => 'doctor05',
'stock' => 50,
'image' => 'doctor05.png',
'info1' => 0,
'info2' => 0,
'input_needed' => 1,
'can_use_item' => 1,
'delete_after_use' => 1,
'category' => 500
),

// 6. - 6th Doctor
array(
'name' => '06th Doctor',
'desc' => 'Doctor Who',
'price' => 50.00,
'module' => 'doctor06',
'stock' => 50,
    'image' => 'doctor06.png',
'info1' => 0,
'info2' => 0,
'input_needed' => 1,
'can_use_item' => 1,
'delete_after_use' => 1,
'category' => 500
),

// 7. - 7th Doctor
array(
'name' => '07th Doctor',
'desc' => 'Doctor Who',
'price' => 50.00,
'module' => 'doctor07',
'stock' => 50,
'image' => 'doctor07.png',
'info1' => 0,
'info2' => 0,
'input_needed' => 1,
'can_use_item' => 1,
'delete_after_use' => 1,
'category' => 500
),

// 8. - 8th Doctor
array(
'name' => '08th Doctor',
'desc' => 'Doctor Who',
'price' => 50.00,
'module' => 'doctor08',
'stock' => 50,
'image' => 'doctor08.png',
'info1' => 0,
'info2' => 0,
'input_needed' => 1,
'can_use_item' => 1,
'delete_after_use' => 1,
'category' => 500
),

// 9. - 9th Doctor
array(
'name' => '09th Doctor',
'desc' => 'Doctor Who',
'price' => 50.00,
'module' => 'doctor09',
'stock' => 50,
'image' => 'doctor09.png',
'info1' => 0,
'info2' => 0,
'input_needed' => 1,
'can_use_item' => 1,
'delete_after_use' => 1,
'category' => 500
),

// 10. - 10th Doctor
array(
'name' => '10th Doctor',
'desc' => 'Doctor Who',
'price' => 50.00,
'module' => 'doctor10',
'stock' => 50,
'image' => 'doctor10.png',
'info1' => 0,
'info2' => 0,
'input_needed' => 1,
'can_use_item' => 1,
'delete_after_use' => 1,
'category' => 500
),

// 11. - 11th Doctor
array(
'name' => '11th Doctor',
'desc' => 'Doctor Who',
'price' => 50,
'module' => 'doctor11',
'stock' => 50,
'image' => 'doctor11.png',
'info1' => 0,
'info2' => 0,
'input_needed' => 1,
'can_use_item' => 1,
'delete_after_use' => 1,
'category' => 500
),
),
array());

// ***** Dalek Item Package *****

global $smcFunc;

// Insert Shop Categories 

$smcFunc['db_insert']('insert''{db_prefix}shop_categories', array(
'name' => 'string',
'id' => 'int',
'count' => 'int'
), 

// Values
array(
'name' => 'The Daleks',
'id' => '501',
'count' => '4'
));

// Insert shop items
$smcFunc['db_insert']('insert''{db_prefix}shop_items'

// Fields
array(
'name' => 'string',
'desc' => 'string',
'price' => 'float',
'module' => 'string',
'stock' => 'int',
'image' => 'string',
'info1' => 'int',
'info2' => 'int',
'input_needed' => 'int',
'can_use_item' => 'int',
'delete_after_use' => 'int',
'category' => 'int'
), 

// Values
array(

// Dalek 1 
array(
'name' => 'Dalek 1',
'desc' => 'Doctor Who',
'price' => 100,
'module' => 'dalek1',
'stock' => 50,
'image' => 'Dalek 1.png',
'info1' => 0,
'info2' => 0,
'input_needed' => 1,
'can_use_item' => 1,
'delete_after_use' => 1,
'category' => 501
),

// Dalek 2
array(
'name' => 'Dalek 2',
'desc' => 'Doctor Who',
'price' => 100,
'module' => 'dalek2',
'stock' => 50,
'image' => 'Dalek 2.png',
'info1' => 0,
'info2' => 0,
'input_needed' => 1,
'can_use_item' => 1,
'delete_after_use' => 1,
'category' => 501
),

// Dalek 3 
array(
'name' => 'Dalek 3',
'desc' => 'Doctor Who',
'price' => 100,
'module' => 'dalekl3',
'stock' => 50,
'image' => 'Dalek 3.png',
'info1' => 0,
'info2' => 0,
'input_needed' => 1,
'can_use_item' => 1,
'delete_after_use' => 1,
'category' => 501
),

// Dalek 4
array(
'name' => 'Dalek 4',
'desc' => 'Doctor Who',
'price' => 100,
'module' => 'dalek4',
'stock' => 50,
'image' => 'Dalek 4.png',
'info1' => 0,
'info2' => 0,
'input_needed' => 1,
'can_use_item' => 1,
'delete_after_use' => 1,
'category' => 501
),

),
array());
?>


Arantor

Well, that's quite correct: you're only providing it four parameters when it needs five.

$smcFunc['db_insert']('insert', '{db_prefix}shop_categories', array(
'name' => 'string',
'id' => 'int',
'count' => 'int'
),

// Values
array(
'name' => 'The Doctors',
'id' => '500',
'count' => '11'
));
]

Parameter 1: string 'insert'
Parameter 2: string '{db_prefix}shop_categories'
Parameter 3: first array
Parameter 4: second array

There is another array required, as the fifth parameter, which should be the primary key(s) of the table in question, for PostgreSQL and SQLite compatibility.
Holder of controversial views, all of which my own.


The Wizard


Arantor

-sigh- No, you have to put in the primary key for your table. If you do not have a primary key, something else is very wrong.
Holder of controversial views, all of which my own.


The Wizard

I know I should be able to figure out what the key is, but I'm not seeing it.

wiz

Arantor

Um, you made the table, therefore you declared what the primary key would be when you made the table.

Or your table doesn't have a primary key and thus nothing works quite exactly as it should anyway...
Holder of controversial views, all of which my own.


The Wizard

I have decided to go with - array( 'key' => '1',) to solve the first error and array( 'key' => '2',) to solve the second error. So what do you think?

Wiz

Arantor

Do you even understand what a primary key is?
Holder of controversial views, all of which my own.


The Wizard

LainaaDo you even understand what a primary key is?

This is what I know:

$smcFunc['db_insert'] (method, table, columns, data, keys, disable_trans, connection)

    Emulated with smf_db_insert
    Method tells how to change the data. Accepts "replace" "ignore" or "insert".
    Table: the data will be changed on.
    Columns: An array ( column_name => input_type) set that holds all column names that will be changed and their expected input type.
    Data holds an array that must be as long as the column array with all the data that will be used.
    Keys is supposed to hold the tables key information, only appears to affect sqlite and postrgresql (when using "replace") versions.

I undertand that $smcFunc['db_insert'] needs 5 things -

Method in my case thats: insert
Table in my case thats: '{db_prefix}shop_categories'
Columns in my case thats: array('name' => 'string', 'id' => 'int', 'count' => 'int'),
Data in my case thats: array('name' => 'The Doctors', 'id' => '500', 'count' => '11')
Keys in my case thats: Not Sure

After doing some more research -
If I understand correctly I need to choose 'name', 'id' or 'count' and set it as the primary key. In this case I choose "id"

the question I'm having now is how to write it in code. Below is how I think it needs to be done -


$smcFunc['db_insert']('insert', '{db_prefix}shop_categories', array('name' => 'string', 'id' => 'int', 'count' => 'int' ),
                array('name' => 'The Doctors', 'id' => '500', 'count' => '11'),
                array(`id`)
                );


Is this correct?

Wiz



margarett

No, you just need to tell the function which is the primary key, it already knows what to do with it ;)


$smcFunc['db_insert']('insert', '{db_prefix}shop_categories', array('name' => 'string', 'id' => 'int', 'count' => 'int' ),
                array('name' => 'The Doctors', 'id' => '500', 'count' => '11'),
                array('id')
                );


If I may add, what you are doing it's not a good principle. The "id" is usually an auto-increment field that you shouldn't handle yourself.
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

LainaaOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Arantor

This is what I mean about a primary key. It's not an SMF thing, it's a fundamental of database design, that represents what the unique identifier within a table is.
Holder of controversial views, all of which my own.


The Wizard

This is my latest attempt given what I know. If it's not this then your going to have to show me, and break it down for the idiot.

Wiz 


$smcFunc['db_insert']('insert', '{db_prefix}shop_categories', array('name' => 'string', 'id' => 'int', 'count' => 'int' ),
                array('name' => 'The Doctors', 'id' => '500', 'count' => '11'),
                array(PRIMARY KEY ('id'))
                );

margarett

Lainaus käyttäjältä: margarett - helmikuu 03, 2014, 07:15:56 AP
No, you just need to tell the function which is the primary key, it already knows what to do with it ;)


$smcFunc['db_insert']('insert', '{db_prefix}shop_categories', array('name' => 'string', 'id' => 'int', 'count' => 'int' ),
                array('name' => 'The Doctors', 'id' => '500', 'count' => '11'),
                array('id')
                );

Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

LainaaOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

The Wizard

If I understand you all I had the right answer a few posts back
array('id')

the answer could have also been
array('id', 'name')

or
[code]array('id', 'name', 'count')

Arantor

Um... no. It is always the name of the primary key of the table, some tables have a composite primary key which is multiple columns.

Look at SMF's database. Many columns outline a primary key, a unique entity within each table. For the topics table, id_topic is the primary key. For the messages table, id_msg is the primary key. These values are necessarily unique within the table. Since the whole point of a relational database is for things to be shown to have relations to other things (one message which lives in one topic which lives in one board which lives in one category), you need references to make them work together, which is what the primary key does.

I strongly suggest you read up on how to actually work with databases before trying to worry about how to do this specific thing.
Holder of controversial views, all of which my own.


The Wizard

I think this is right? ???

array('name' => 'id', 'type' => 'primary', 'columns' => array('id'), ),

Arantor

Well, that makes the id column the primary key but it's quite clear you have no idea what a primary key or why it is important for dealing with databases. Please for both our sakes, go and read up on it.
Holder of controversial views, all of which my own.


Advertisement: