Uutiset:

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

Main Menu
Advertisement:

Replacing multiple values in database with smcFunc 'replace'.

Aloittaja MrMorph, marraskuu 22, 2013, 10:37:52 AP

« edellinen - seuraava »

MrMorph

I tried searching but could not find the information I need.

I'm just wondering what is the best way of replacing a number of records at one time with the smcFunc 'replace' function.

So say I have a load of database records and then I have an array that contains what I want to change those records to.

Is the 'replace' method limited to handling one query at a time meaning I would need to loop through the array holding the new data and do it piecemeal ?

Or somehow can I just incorporate my array of new values into the smcFunc call ?

Thanks for any hints :)

MrMorph

#1
For example, how would I emulate this basic MYSQL query as a starter :

INSERT INTO tbl_name (a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9);

MrMorph

Never-mind, I figured it out with some experimenting. For anyone else you can do this :

$query = $smcFunc['db_insert']('replace', "
{db_prefix}my_table",
array(
'id' => 'int',
'value' => 'string',
),
array(
array(24,'stringone'),
array(28,'stringtwo'),
array(30,'someotherstring'),
),
array('id'));

emanuele



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: