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 9002667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:36:06+00:00 2026-06-16T00:36:06+00:00

I have a large database (28k entries in this particular table one table) and

  • 0

I have a large database (28k entries in this particular table one table) and I need to append some HTML tags to the front and back of every column in a table.

Here is my code:

try
{
    $conn = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
    if(!$conn)
    {
        echo "Error in connecting to the database.";
    }
    $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING );  

    $query = $conn->query("SELECT `id`, `introtext` FROM *TABLE* WHERE id >= 41155");
    $query->setFetchMode(PDO::FETCH_OBJ);

    //For each row in the table
    while($row = $query->fetch())
    {
        $introtext = '<span class="*SPAN CLASS*">' . $row->introtext . '</span>';
        $update_query = $conn->prepare("UPDATE *TABLE* SET introtext = ? WHERE id = ?");

        if ($query->execute(array($introtext, $row->id))) 
            echo $row->id . " Done <br>";
        else 
            echo $row->id . " Err<br>";
    }

} catch(PDOexception $e) {
    echo $e->getMessage();
}

$conn = null;

When I run the script, it outputs 41155 Done 4132 times. I’m not sure the logic here, but any help to get this working is appreciated.

  • 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-06-16T00:36:06+00:00Added an answer on June 16, 2026 at 12:36 am

    I agree with Dagon that the database is not the place for that (what if tomorrow you decide that <span> should wrap another HTML tag?).

    Anyway, it sounds like a one-time operation, so I wouldn’t use PHP. Just run a MySQL client (the command line mysql, or Workbench, and use a query like this:

    UPDATE *TABLE* 
    SET introtext = CONCAT('<span class="*SPAN CLASS*">', introtext, '</span>') 
    WHERE id >= 41155
    

    One note about your current code: you’re never executing the UPDATE query! You just prepare the statement, then instead of executing $update_query, you’re executing $query again! That’s why you’re always printing the same id.

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

Sidebar

Related Questions

I have one large database table of request data, much like Apache request logs,
I have a large database table that I need to display on a Windows
I have a very large database with about 120 Million records in one table.I
I have a large database and for one of the table I want to
I'm using very large database, some of tables have more than 30.000.000 entries, now
I have large database table, approximately 5GB, now I wan to getCurrentSnapshot of Database
I have a large database of resumes (CV), and a certain table skills grouping
I have a large database (~2700 entries) of vocabulary. Each row contains an English
I have a large database I need to populate with data before initially running
I have a large database and would like to select table names that have

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.