-3

I have a large-ish amount of server-side data that I need to store in a mySQL table. [I'm a novice, working through the learning curve of javascript & php.]

I'm thinking it's best to stringify the javascript array into a JSON object and send that to a PHP page to save to the database. Once the data's in a PHP array, I know how* to get it into the database; I'm just not sure what's the best way to get it there.

I can't POST (like this example) since the maximum length of a POST string is 2048 characters, and I have maybe 10-20kb of data.

I'd rather not use AJAX or Node.js (like this example) for the sake of simplicity, and since this is a one-off (but both on my list to learn in the future!)

Or, would it be best to create a temp text file to the server with javascript, and then call a PHP page to load & process the data? (Although I can't find examples of how to do that without using POST.)

I understand the difference between server-side & client-side (thanks to this great explanation) but the size limit of POST seems to be my issue?

*Also I'm a little unsure as to when/how it's necessary to encode data (like with this deprecated mysql-real-escape-string example) for storage with {json/posting/DB tables/text}. In this case my data could contain 'single' & "double" quotes (but no foreign characters 国外 वर्ण), which [in my short experience] seem like the only times it will be an issue?

Thanks!

ashleedawg
  • 20,365
  • 9
  • 72
  • 105
  • 1
    I'm not sure what you mean, `I have a large-ish amount of server-side data`, do you have the data on the server already? – jeroen Oct 10 '17 at 07:50
  • You can post it of you break it up? You are then limited by the max post setting in php.ini and if that is incredibly high which i would hope not you are limited by the memory available. chunk it up into an acceptable size, loop the post data and put it back together server side to store. – CodingInTheUK Oct 10 '17 at 07:53
  • I missed the server-side part, you don't need to post it if its there already, you just need to insert it into your database in a large format, probably blob is what you are looking for. – CodingInTheUK Oct 10 '17 at 07:55

1 Answers1

2

The problem is that Javascript is client side language while PHP is server side language. This means that PHP cannot interact with the user without some HTML, CSS or JavaScript and visa-versa, JavaScript can't interact with server side files without some PHP. Why is this? Since JavaScript is client side the user can edit it as they can see the code while with a PHP script it is all on the server and they are not able to see the code, only what it outputs/prints. So in short you cannot do what you are asking without POST or GET and it is not possible to do this without a server side script such as a PHP script (Python is also very useful if you are thinking of learning more about web backends).

There are numerous example of how to do this that you can find with a simple google search, here is a great example send data to MySQL with AJAX + jQuery + PHP

Hope I could clarify your question.