Jump to content

reducing queries - mysql insert & foreach


perky416

Recommended Posts

Hi everyone.

 

Iv touched on something similar to this before however having come back to it after a while i dont fully understand it.

I have a website where people can add their domains. They add multiple domains in a text area. I have code that splits up each line of the text box and validates each domain etc...that is all working fine. Below is the code that I currently use to insert each domain into the database.

If the user adds 100 domains, i take it that the code below will execute 100 queries to write each domain?

 

Is it possible to execute only 1 query and add all the domains, each to a new row in the database?

 

$not_exists = array_diff(array_map('trim', $lines), $exists);
foreach ($not_exists as $domain){
mysql_query("INSERT INTO domains VALUES("'$domain'");
}

 

Thanks

Link to comment
Share on other sites

Hi mate,

Thanks for the tip however that wasn't really what I was looking for. Im hoping to do it just by altering the code if its possible. I could have loads of users adding loads of domains all at the same time. I don't really want to be creating files on the server.

Thanks anyway.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.