Save an object to another database

19 views
Skip to first unread message

Emiel B.

unread,
Jan 3, 2013, 10:46:01 AM1/3/13
to php-object...@googlegroups.com
Hi,

I'm quite a beginner with POG, and I'm searching for some help. Here's my problem:

- I want to read an object from a database, make some changes and move it to another database.

Here's the correct process I guess:
  1. Load Object1
  2. Modifiy Object1
  3. Clone Object1 to Object2
  4. Delete Object1 from Database1
  5. Connect to Database2
  6. Save Object2 into Database2
I dont't know how to disconnect and connect to a new Database (step 5). I have made a second configuration.php file, but I don't know how to use it. Do you have some tips to do that? Is POG not meant for that at all?

Thank you!

Mario

unread,
Jan 18, 2013, 6:41:20 AM1/18/13
to php-object-generator
Hi Emiel.

You might need a modified version of database class with two methods (Reset is a new one and Connect has been) like these:




 

public static function Reset() {
if (isset(self::$database) && self::$database != NULL)
mysql_close(self::$database->connection);
self::$database  = NULL;
}

public static function Connect()
{
if (!isset(self::$database) || self::$database==NULL)
{
self::$database = new Database();
}
return self::$database->connection;
}




Then you can use them like this:


include ('firstconfig.php');

$object = new objectclass();

$objs = $object->GetList(array(array('field','>',1)));

Database::Reset();

include ('secondconfig.php');

foreach($objs as $obj){

    //take care of ids

    $obj->SaveNew();

}

Database::Reset();

include ('firstconfig.php');



You need to do a Database::Reset() before use another database.

I hope this can do the trick.


Have a nice day!



 




--
You received this message because you are subscribed to the Google Groups "Php Object Generator" group.
To view this discussion on the web visit https://groups.google.com/d/msg/php-object-generator/-/L-00ivXDWJ0J.
To post to this group, send email to php-object...@googlegroups.com.
To unsubscribe from this group, send email to php-object-gener...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/php-object-generator?hl=en.



--



«Si la depuración es el proceso de eliminar errores, entonces la programación debe ser el proceso de introducirlos.» -- Edsger W. Dijkstra

Reply all
Reply to author
Forward
0 new messages