PowWeb Forums - The Perfect Community for the Perfect Host  

Register now to interact with over 11,000 members! Registered users have Posting Privileges, free access to Private Messaging, Email Notifications and more.

Go Back   PowWeb Community Forums > The PowWeb Platform > MySQL
User Name
Password
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools
Old 7-15-16, 07:17 PM   #1
PeterPan
 
Join Date: Sep 2002
Location: Auckland
Posts: 1,341
Reputation: 89
How to do multiple inserts ?

Hello.

Im wondering waht is the best / 'propper' way to do multiple inserts of data into MYSQL.

Ive got anywhere from a few dozen - to hundreds to do.

Is it safe to

:-Open the MYSQLI database

- do a foreach loop

- insert on update etc....

end loop

- close the MYSQLI database.


is it safe / propper to insert a lot of Inserts like this in one go ?




PS - I can / know how to do this in steps - IE one insert every 5 mins until all of them done... But i'm looking for a faster way, but not sure how far i can go

Last edited by PeterPan; 7-15-16 at 07:19 PM.. Reason: Spalling mispikes
PeterPan is offline   Reply With Quote
Old 7-15-16, 08:24 PM   #2
snowmaker
target='_blank'
 
snowmaker's Avatar
 
Join Date: Nov 2002
Location: Not in Solomons anymore.
Posts: 3,433
Reputation: 326
My database coding knowledge is nearly non existent, but in any other coding languages that I know, I would opt for some kind of loop to do that type of operation.
__________________
-bruce /* somdcomputerguy */
'If you change the way you look at things, the things you look at change.'
snowmaker is offline   Reply With Quote
Old 7-15-16, 08:36 PM   #3
PeterPan
 
Join Date: Sep 2002
Location: Auckland
Posts: 1,341
Reputation: 89
The process is easy enough to do _ The question i'm asking is - Is it safe to do 10 at a time? 100 at a time ? 1000 at a a time ? 10,000 at a time ?

$sql="INSERT INTO `nwcategories` (`CatLatest`, `CatUNIQUE`, `CatReference`, `CatCategory`)
VALUES(NOW(), \"$unique\", \"$ID\", \"$ax\") ON DUPLICATE KEY UPDATE `CatLatest`=NOW()";

(do / process SQL)

$sql="INSERT INTO `nwcategories` (`CatLatest`, `CatUNIQUE`, `CatReference`, `CatCategory`)
VALUES(NOW(), \"$unique\", \"$ID\", \"$ax\") ON DUPLICATE KEY UPDATE `CatLatest`=NOW()";

(do / process SQL)

$sql="INSERT INTO `nwcategories` (`CatLatest`, `CatUNIQUE`, `CatReference`, `CatCategory`)
VALUES(NOW(), \"$unique\", \"$ID\", \"$ax\") ON DUPLICATE KEY UPDATE `CatLatest`=NOW()";

(do / process SQL)

$sql="INSERT INTO `nwcategories` (`CatLatest`, `CatUNIQUE`, `CatReference`, `CatCategory`)
VALUES(NOW(), \"$unique\", \"$ID\", \"$ax\") ON DUPLICATE KEY UPDATE `CatLatest`=NOW()";

(do / process SQL)

$sql="INSERT INTO `nwcategories` (`CatLatest`, `CatUNIQUE`, `CatReference`, `CatCategory`)
VALUES(NOW(), \"$unique\", \"$ID\", \"$ax\") ON DUPLICATE KEY UPDATE `CatLatest`=NOW()";

(do / process SQL)

Close MYSQL... (in a loop)
PeterPan is offline   Reply With Quote
Old 7-15-16, 08:42 PM   #4
snowmaker
target='_blank'
 
snowmaker's Avatar
 
Join Date: Nov 2002
Location: Not in Solomons anymore.
Posts: 3,433
Reputation: 326
Well I couldn't really say if it's safe or not safe. I know that loops are a lot easier to write and manage.. I'm sure that someone with more MySQL coding experience could tell you, perhaps going to a database forum would get you a quicker answer..
__________________
-bruce /* somdcomputerguy */
'If you change the way you look at things, the things you look at change.'
snowmaker is offline   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 08:17 AM.


Contents ©PowWeb, Inc. ~ vBulletin, Copyright 2000-2007 Jelsoft Enterprises Limited.