Skip to main content
deleted 28 characters in body; edited tags; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

Is there Saving and uploading images in a more efficient way of executing PDO statements?database

I am working on a small method that saves uploaded images and records the images in a database.

public function setEventImages($event_id){
            foreach($_FILES['event-images']['tmp_name'] as $tmp_name){ 
                $imgName = $this->imgPath . $this->random_name . $_FILES['event-images']['name'];
                move_uploaded_file($tmp_name, $imgName);
                $stmt = $this->dbh->prepare("INSERT INTO adrenaline_junkies_uk_event_images (event_image_name, event_id) VALUES (?,?)");
                $stmt->bindParam(1, $imgName, PARAM_STR);
                $stmt->bindValue(2, $event_id, PARAM_INT);
                $stmt->execute();
            }
        }

I was wondering if there was aHow can this be made more efficient way of doing this?

Is there a more efficient way of executing PDO statements?

I am working on a small method that saves uploaded images and records the images in a database.

public function setEventImages($event_id){
            foreach($_FILES['event-images']['tmp_name'] as $tmp_name){ 
                $imgName = $this->imgPath . $this->random_name . $_FILES['event-images']['name'];
                move_uploaded_file($tmp_name, $imgName);
                $stmt = $this->dbh->prepare("INSERT INTO adrenaline_junkies_uk_event_images (event_image_name, event_id) VALUES (?,?)");
                $stmt->bindParam(1, $imgName, PARAM_STR);
                $stmt->bindValue(2, $event_id, PARAM_INT);
                $stmt->execute();
            }
        }

I was wondering if there was a more efficient way of doing this?

Saving and uploading images in a database

I am working on a small method that saves uploaded images and records the images in a database.

public function setEventImages($event_id){
            foreach($_FILES['event-images']['tmp_name'] as $tmp_name){ 
                $imgName = $this->imgPath . $this->random_name . $_FILES['event-images']['name'];
                move_uploaded_file($tmp_name, $imgName);
                $stmt = $this->dbh->prepare("INSERT INTO adrenaline_junkies_uk_event_images (event_image_name, event_id) VALUES (?,?)");
                $stmt->bindParam(1, $imgName, PARAM_STR);
                $stmt->bindValue(2, $event_id, PARAM_INT);
                $stmt->execute();
            }
        }

How can this be made more efficient?

Tweeted twitter.com/#!/StackCodeReview/status/383248856873713664
Source Link
crmepham
  • 657
  • 2
  • 9
  • 16

Is there a more efficient way of executing PDO statements?

I am working on a small method that saves uploaded images and records the images in a database.

public function setEventImages($event_id){
            foreach($_FILES['event-images']['tmp_name'] as $tmp_name){ 
                $imgName = $this->imgPath . $this->random_name . $_FILES['event-images']['name'];
                move_uploaded_file($tmp_name, $imgName);
                $stmt = $this->dbh->prepare("INSERT INTO adrenaline_junkies_uk_event_images (event_image_name, event_id) VALUES (?,?)");
                $stmt->bindParam(1, $imgName, PARAM_STR);
                $stmt->bindValue(2, $event_id, PARAM_INT);
                $stmt->execute();
            }
        }

I was wondering if there was a more efficient way of doing this?