www.webdeveloper.com
Results 1 to 3 of 3

Thread: Error at Sending multiple database queries

Hybrid View

  1. #1
    Join Date
    Oct 2008
    Posts
    2

    Error at Sending multiple database queries

    Hello there. Iencounter the following problem:

    The following scenario:

    I got a class, wich saves pictures and assigns a gallery to the picture and a function in the picture-class which writes a new sort index into the same database table.

    PHP Code:
    class picture {
         function 
    save() {
              
    getDB()->sendQuery(insert into pictures...);
              
    $gallery = new gallery();
              
    $gallery->update();
         }
         function 
    sort() {
              
    getDB()->sendQuery(Select gallery from pictures ...);
              
    getDB()->sendQuery(Update pictures set sortindex ...);
         }
         function 
    activate() {
             
    $this->save();
             
    $this->sort();
         }


    }
    class 
    gallery {
         function 
    update() {
              
    getDB()->sendQuery(update pictures set gallery = ...);
         }

    if i do this for one photo, it works without any problems...BUT...if i run this for more photos in a foreach{} it stops sometimes after the first, sometimes after the second picture and tells me, that the query

    SELECT gallery from pictures...

    in the sort-function is not valid, as there is no valid gallery.
    it seems, that the table is not updated yet.

    if i add a small delay like

    PHP Code:
    function activate() {
             
    $this->save();
             
    sleep(2);
             
    $this->sort();
         } 
    it works fine for all pictures in my foreach{}. It seems, that PHP is not waiting till the save() is finished prior it calls activate().

    Is it a problem, that i use different classes for it? are they working independent? Is there a possibility to say PHP it should wait till the save() of the picture class is finished?

    Anyone an idea?
    Thanks a lot.

  2. #2
    Join Date
    Sep 2008
    Posts
    408
    Try:

    PHP Code:
    function activate() { 
             if(
    $this->save()) {
                 
    $this->sort();
             }
         } 
    And have $this->save() return TRUE at the end of the function if all goes as planned.

  3. #3
    Join Date
    Oct 2008
    Posts
    2
    $this->save() returns every time the Insert(or Update)-ID of the picture

    i tried:

    PHP Code:
    function activate() {
             
    $rc $this->save();
             if(
    $rc) {
                 
    var_dump($rc);
                 
    $this->sort();
             }

    but this returns sometimes 1, sometimes 2 IDīs but also wont work for more than 1 picture...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles