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

  • SEARCH
  • Home
  • 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 7625085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:08:43+00:00 2026-05-31T05:08:43+00:00

I’m working on a school project creating a CMS for my portfolio site. I

  • 0

I’m working on a school project creating a CMS for my portfolio site. I am having trouble getting my update function to work. I have a feeling it has something to do with the way I’m constructing my PDO Transaction. In my database I have a projects table, category table, and the associative content_category table. I’m able to insert my projects into those tables just fine. What I want to do is insert into my projects table then delete all records from the content_category table and finally insert the current category records into that associative table to complete the transaction. I do get my return statement “Project Updated” returned. But the tables aren’t being updated. Any ideas anyone?

Here’s the code:

This is a function in my Project class.

public function update(){
    try {
        $conn = getConnection();
        $conn->beginTransaction();
        $sql = "UPDATE project 
                SET project_title = :title, 
                    project_description = :desc, 
                    project_isFeatured = :feat, 
                    project_mainImage = :image
                WHERE project_id = :id";
        $st = $conn->prepare($sql);
        $st->bindValue(":id", $this->id, PDO::PARAM_INT);
        $st->bindValue(":title", $this->title, PDO::PARAM_STR);
        $st->bindValue(":desc", $this->description, PDO::PARAM_STR);
        $st->bindValue(":feat", $this->isFeatured, PDO::PARAM_BOOL);            
        $st->bindValue(":image", $this->mainImage, PDO::PARAM_INT);
        $st->execute(); 

        $sql = "DELETE from content_category
                WHERE content_id = :id";
        $st = $conn->prepare($sql);
        $st->bindValue("id", $this->id, PDO::PARAM_INT);
        $st->execute();

        $sql = "INSERT into content_category (content_id, cat_id)
                VALUES (?,?)";
        $st = $conn->prepare($sql);

        foreach($this->categories as $key=>$value){
            $st->execute(array(intval($projectID), intval($value)));                                        
        }
        $conn->commit();
        $conn = null;
        return "Project updated";                   
    }
    catch(Exception $e) {
        echo $e->getMessage();
        $conn->rollBack();
        return "Error... Unable to update!";
    }
}
  • 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-31T05:08:44+00:00Added an answer on May 31, 2026 at 5:08 am

    In order to make sure you are not encountering a PDO error, you should set the PDO error reporting like this:

    $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    

    There are functions in PDO such as prepare() which will either return false or throw a PDOException depending on what error mode is set. This way, it will throw an exception and you’ll definitely know if you are having a problem!

    Also, if your database doesn’t support transactions (like MyISAM), the beginTransaction() function will return false. So, maybe add a check in there like:

    if($conn->beginTransaction()) {
       // Do transaction here
    } else {
       echo("Unable to use transactions with this database.");
    }
    

    Oddly enough, according to PHP documentation, you would be getting an exception if your database doesn’t support transactions…

    Unfortunately, not every database supports transactions, so PDO needs to run in what is known as “auto-commit” mode when you first open the connection. Auto-commit mode means that every query that you run has its own implicit transaction, if the database supports it, or no transaction if the database doesn’t support transactions. If you need a transaction, you must use the PDO::beginTransaction() method to initiate one. If the underlying driver does not support transactions, a PDOException will be thrown (regardless of your error handling settings: this is always a serious error condition).

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

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.