Example of dataarray:
//rec 0;
$dataarray[0]['yourfield1']="Somevalue...";
$dataarray[0]['yourfield2']="Some other value...";
$dataarray[0]['yourfield3']="Some third value...";
//rec 1;
$dataarray[1]['yourfield1']="Somevalue 1...";
$dataarray[1]['yourfield2']="Some other value 1...";
$dataarray[1]['yourfield3']="Some third value1...";

You may also need using utf8_encoding. Example:
function array_utf8_encode_(&$item, $key)  { $item=utf8_encode
($item); }
array_walk_recursive($arr,'array_wtencode');
echo json_encode($arr);


On Feb 9, 2:03 pm, "Tosca Lahiri" <[email protected]> wrote:
> Thanks for this advice.
> In the php code is the $dataarray made up of:
> [fieldname, value]?
>
> I have found the xml tutorial you suggested...it is very good. That is what
> made me go down the xml route. I can see now however why the json option is
> preferable.
> TML
>
> -----Original Message-----
> > From: [email protected] [mailto:[email protected]]
> > On Behalf Of Oblygre
> > Sent: Monday, February 09, 2009 6:41 AM
> > To: Gears Users
> > Subject: [gears-users] Re: MYSQL XML SQLITE
>
> > I think its easier to use json istead of xml, this saves a lot of time
> > in javascript, and PHP have built in functions to convert to json.
>
> > Example:
>
> > In your php script:
> > echo json_encode($dataarray); // $dataarray contains all your db data
>
> > In your gearscode:
> >  //data from server is saved in serverresponse
> >  //
> >  try {
> >        eval("dataarr="+serverresponse);
>
> >       }
> >    catch (ex) {
> >       alert("Error: No valid data found..");
> >       return;
> >     }
>
> > var dbcount=0;
> > var reply="no reply";
> > var db ;
> > db= google.gears.factory.create('beta.database');
> > if (db) {
> >   db.open('yourdatabase');
> >   db.execute('begin');
> >   db.execute('drop table if exists yourtable');
> >   db.execute('create table if not exists yourtable' +
> >            ' (yourfield1, yourfield2, yourfield3, primary key
> > (yourfield1))');
> >   for (x in dataarr)
> >     {
> >     db.execute('insert into yourtable values(?,?,?)',
> >         [dataarr[x].yourfield1,dataarr[x].yourfield2,dataarr
> > [x].yourfield3];
> >     dbcount++;
> >     //if (dbcount%100==0)
> >       //wp.sendMessage(dbcount+" record(s) added....",
> > message.sender);
> >     }
> >   }
> > db.execute('commit');
> > db.close();
> > reply=dbcount+" record(s) added from main DB, finished";
>
> > A link to a tutorial using XML:
> >http://www.onlamp.com/pub/a/onlamp/2007/06/28/the-power-of-google-gears-
> > part-1.html
>
> > On Feb 8, 2:37 am, TML <[email protected]> wrote:
> > > Just to clarify...I mean programmatically, not a one off with a tool.
> > > When the user goes online on their pda the data is imported into the
> > > locally held sqlite db.
>
> > > On Feb 8, 1:34 am, TML <[email protected]> wrote:
>
> > > > Hello,
>
> > > > I have a MySQL DB on web server. I have php page that extracts the
> > > > data from table and creates an XML file.
>
> > > > Now, I need to know how to import that data in the XML file into the
> > > > Gears sqlite DB on PDA?
>
> > > > Any suggestions?
>
> > > > Thanks,
> > > > TML

Reply via email to