I’m using JSON database and I have a question?

Asked

Viewed 153 times

-1

I have a JSON database of users, for example, if I update my username via AJAX POST, click update and call AJAX exchange the value based on my ID with PHP, all right.

Ai enters the doubt in PHP processing I give overwrite in the bank, ie, save it on top of the other replacing.

In a real demand of hundreds of users updating the username at the same time in the same JSON database and possible bugs?

In SQL you have Sqlquery that avoids bugs (I think) but in JSON databases what would be the smartest way to use?

Only process this overwhite after the user closes the page? thus processing the database update only once instead of every time you click update some data call AJAX immediately?

  • 1

    JSON is an encoding format, not a database. You’re writing JSON to a file on the server, is that it? I think the natural way is to migrate to a Nosql database that represents the data in a hierarchical way, very similar to JSON.

  • Use JSON as the same database, in php dou file_get_contents('arquivojson') and store in a variable then json_decode changes the values coming from the front and saved again with json_encode and file_put_contents('arquivojson');

  • I know maybe it’s not the best way, and just a doubt!

  • In the case of multiple requests at the same time of a file_put_content() saving the same file, as PHP would behave?

  • I’m sure it’ll give M. At best, if two or more lawsuits write the file, only one survives. If everyone was making changes, only the change of the lucky process survives.

  • I can not understand when the staff negative these questions, he IS BEGINNER, do not know what works, if the site was for people 100% experienced, there would be no questions and answers. My opinion...

Show 1 more comment

1 answer

0


Hello,

The JSON (acronym for: Javascript Object Notation) is a lightweight file format for exchanging messages between systems, not a database. Its popularity is mainly due to its simplicity of reading and writing in many languages. When you want to rewrite something in a JSON file you should basically take the old content, change what you want and rewrite the file with the new content. There’s no way out of it.

In a scenario with a large number of data, taking old content, editing it and writing it again can take a few milliseconds. However this means x milliseconds by "query", which makes it impossible to use it in a real environment. For this reason JSON is not the best option when it comes to replacing a database (and we’re not even talking about security yet). However, if you still want to use it, try to break into some files such as tables. And when executing "queries", look directly for the corresponding file that "table". This solution offers neither the security nor the speed of a database, but it is your choice whether or not to use this method.

I hope I helped, hug.

  • And that my project is small... I just want a user registration/login system n I believe will have more than one user registering simultaneously

  • However I have nothing to lose using a "truth" comic,, I will mark as solved thank you very much

Browser other questions tagged

You are not signed in. Login or sign up in order to post.