Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6232901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:12:03+00:00 2026-05-24T10:12:03+00:00

I need to optimize a script for high performance so the question is how

  • 0

I need to optimize a script for high performance so the question is how can I add MySQL multi-query to this code?

foreach($multiContent as $htmlContent) {
    $email = urldecode($email['1']);
    $user = $user['1'];

    //store in db
    $db->query("UPDATE eba_users 
                   SET mail = '$email' 
                 WHERE username = '$user'");
    //echo "email is $email and user is $user\n";
  }

  //close if ($array_counter % 200
  unset($array_counter);
  unset($data);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T10:12:04+00:00Added an answer on May 24, 2026 at 10:12 am

    If you’re using mysqli or PDO already, you should be using prepared statements for your queries since they are supported. This will also have a slight increase in performance since the entire query doesn’t need to be sent again to the DB server. However the biggest advantage is the increased security that prepared statements provide.

    Other than this, try adding an index on username to speed this query up if you haven’t already.

    Edit:
    If you want to do it all in one query, as you seem to suggest, you could also use ON DUPLICATE KEY UPDATE as mentioned as an answer to this question:

    INSERT INTO eba_users (`username`, `mail`) 
    VALUES 
        ('username1','$email1'),
        ('username2','$email2'),
        ('username3','$email3'),
        ('username4','$email4'),
        ....
        ('usernameN','$emailN'),
    ON DUPLICATE KEY UPDATE `mail`=VALUES(mail);
    

    However this may not be as fast as using prepared statements with a regular UPDATE.

    Edit2: As requested, here is probably a close approximation of what you should be doing to bind the parameters in mysqli:

    if ($stmt = $mysqli->prepare("UPDATE eba_users SET mail= ? WHERE username= ?")) {
    
        /* loop through array of users */
        foreach ($array as $username => $newemail) {
    
            /* bind parameters for markers */
            $stmt->bind_param("ss", $newemail, $username);
    
            /* execute query */
            $stmt->execute();
        }
    }
    

    Of course this doesn’t provide any sort of error messages in case this fails. For that, you can look into mysqli::error

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I optimize this code ? I made IPFilter and I need to
i need optimize this query, please see the comented line: SELECT p.NUM_PROCESSO, p.NUM_PROC_JUD, p.Num_Proc_Jud_Antigo1,
I need to optimize code to get room for some new code. I do
I'm in a need to optimize this really tiny, but pesky function. unsigned umod(int
I am have a lot of code that I need to optimize and make
< backgound> I'm at a point where I really need to optimize C++ code.
I need to optimize some code where I multiply a vector of ints (32
I'm using JasperReporting engine, and i need to optimize reporting performance. Currently my application
I need to optimize a query that is being produced by a save (insert
We need to optimize the text rendering for a C# Windows Forms application displaying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.