Jump to content

Javascript read SQL


Fritz_Doll

Recommended Posts

yes. Javascript has no native way to interface with a database because it is only meant to run on the client side. Hence why one needs a server side language like PHP in order to interface with a database, and then using AJAX to get Javascript to communicate with PHP.

Link to comment
Share on other sites

To make matters worse:HTML 5 was until VERY recently going to have a clientside database ability, but the working group disagreed with the browser folk about the implementation of SQL, so work has now halted.

Link to comment
Share on other sites

To make matters worse:HTML 5 was until VERY recently going to have a clientside database ability, but the working group disagreed with the browser folk about the implementation of SQL, so work has now halted.
Do you mean as in being able to interface with an SQL database natively? Like XMLHttpRequest Object for database interaction?
Link to comment
Share on other sites

If you're thinking this was to be a direct socket to your server DB, no.My understanding is that it was to live on the client, analogous to cookies and the new web storage functionality. I assume the API would have interfaced with an engine native to your browser and OS. But the note on this document is very depressing, at least for anyone who likes the idea of local DB support.I doubt I would have used it for anything serious. Users want to access their stuff from their choice of computers, not just the one at work or home. (Is there such a thing as a "distributed client" model?) But if you wanted a system for longer, more structured cookies, this might have been okay.

Link to comment
Share on other sites

I think I remember reading in the SQL manual or possibly else where that you can save the DB in three formats when you dump it into a file xml, sql and txt (not sure if my memory is correct there) but could I get help finding that? Because if that's the case then I can use PHP to input the data into a SQL DB then i can dump it into an XML sheet and use AJAX to read the XML.

Link to comment
Share on other sites

I think I remember reading in the SQL manual or possibly else where that you can save the DB in three formats when you dump it into a file xml, sql and txt (not sure if my memory is correct there) but could I get help finding that? Because if that's the case then I can use PHP to input the data into a SQL DB then i can dump it into an XML sheet and use AJAX to read the XML.
why would you want to convert it to XML, instead of using PHP to fetch the content back from the DB? I could understand if you were serving up a third party API or something and wanted to offer a response format in XML.
Link to comment
Share on other sites

If your data starts off as XML, you will be able to use the new data storage functionality to save a serialized (string) copy of your XML and just ignore the whole SQL step. I have some apps where I save a big chunk of data as an XML file on the server. I ship the whole file to my client through AJAX. JavaScript uses XML DOM methods to manipulate the data. On browsers where it's available, I serialize the XML and save a backup copy right on the client. (Useful for recoveries.) When the user wants to save, the XML gets serialized and AJAXed back to the server, where it is simply saved as a file again. PHP never accesses the XML as XML, and no SQL ever comes into the picture. Where the chunks of data are relatively small (less that 50K) I find this extremely efficient.

Link to comment
Share on other sites

Could you show me how to do that or post a link that would explain it. Because the information that would be sent from the client to the server would be small to start with. I'm trying to build my website with as much Javascript/AJAX as possible. Also what browser support that? I'm thinking maybe the newer versions of most major browsers.

Link to comment
Share on other sites

There is nothing mysterious about retrieving an XML file through AJAX. Assuming the transmission is successful, AJAX automatically turns an XML data string into an XML DOM object. The DOM methods like getElementsByTagName are pretty straightforward also, if you have worked with DOM objects before.What is harder to find documentation on is the process of serializing XML into string data. This little function handles that:

function xml2string (d) {		   // where d is an XML DOM object   var s;   if (window.XMLSerializer) {	  // Mozilla, Webkit, Opera	  s = new XMLSerializer();	  return s.serializeToString(d);   } else {						 // Explorer	  return d.xml;   }}

You might want to add a line of code to the top of the function to verfiy that d is in fact an object. (I think I have other implementations that do that. I just copy/pasted code from the handiest file I had.) In any case, if it returns false or an empty string, your calling function will know it didn't work.

Link to comment
Share on other sites

I serialize the XML and save a backup copy right on the client. (Useful for recoveries.)
where do you make a copy on client? what do you mean by that?
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...