Request for feedback: RemoteDataObject package
| From: | Yahoo) | Date: | Wed, 02 Jul 2003 17:30:45 +0000 |
| Subject: | Request for feedback: RemoteDataObject package | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-17936@lists.php.net to get a copy of this message | ||
Hi,
I had the problem that I wanted to access a database at my web hoster's
machine.
The only interface I had was a web interface. To be able to synchronise a
local database to a remote one via XML-RPC, I wrote a class
DB_RemoteDataObject giving me the following methods:
remote_count ()
remote_delete ()
remote_delete_selection ()
remote_get ()
remote_get_selection ()
remote_insert ()
remote_insert_selection ()
remote_query ()
remote_select ()
remote_update ()
remote_update_selection ()
What you basically do is:
- prepare the DB_RemoteDataObject by :
// create the RemoteDataObject
$remote_HLBA_contact = new DB_RemoteDataObject;
// set the xml-rpc client it is going to communicate with (same
signature as XML_RPC_Client constructor)
// make sure it points to your server script :-)
$remote_HLBA_contact->set_XML_RPC_Client("/tests/xmlrpc/server.php",
"www.somemachine.com", 80);
// create a DB_DataObject child object (in this case,
HLBF_Tbl_Contact inherits from DB_DataObject)
$HLBA_contact = new HLBF_Tbl_Contact;
//use this DB_DataObject to communicate with the local database, or
to retrieve results
$remote_HLBA_contact->set_DB_DataObject($HLBA_contact);
//assign the remote dns (a logical name for a DataObject serverside
$remote_HLBA_contact->remote_dns = "HLBF_Tbl_contact";
- use the methods remote_count, remote_delete, remote_get, remote_insert,
remote_query, remote_update in exactly the same way as you would do with
their local equivalents:
- prepare the $remote_HLBA_contact->DB_DataObject by setting
properties or using the whereAdd, Limit, etc method...
- send it to the server by
$result = $remote_HLBA_contact->remote_update();//and analogous
-the return value is an int, a DB_DataObject, an array of
DB_DataObjects, or a pear error
- use the method remote_select as you would do with the find() method, with
that exception that you get an array of DB_DataObjects as resultset, without
having to call the fetch() function
- use the methods remote_delete_selection, remote_get_selection,
remote_insert_selection, remote_update_selection to first retrieve a dataset
locally (by preparing $remote_HLBA_contact->DB_DataObject in exactly the
same way as before a find() method), and send delete, retrieve, insert or
update the corresponding dataset remotely (corresponding means: the records
with the same primary keys).
What you need:
- a client script including DB/RemoteDataObject.php (example is included)
- a server script including DB/RPC/RemoteDataObjectServer.php and defining
the logical datasource names to be used in rpc-calls by indicating the
DB_DataObject ini file location, the class script location and the class
name (example included)
- a working DB_DataObject child class both locally and remotely (typically
the same, however they can be different, as long as the column names of the
table described are identical server- and client side). In the example,
class "HLBF_Tbl_Contact" in Tbl_contact.php is used.
I hope this code can be of use to you. I'm new at programming
pear-compliant stuff (and no fulltime developer either), so there will be a
lot to improve. However if you think this is usefull, I'll be glad to
commit it to pear.
Pascal Van Hecke
Attachment: [application/x-zip-compressed] RemoteDataObject.zip
Attachment: [application/x-zip-compressed] RemoteDataObject.zip