Is it a good thing to convert all MySQL Database to JSON when viewing websites.
I am able to create a PHP script to Javascript that will create variables for each tables in the database with JSON structure in each with information. I found this to be a lot quicker to code information on page from MySQL. But I just wondering if that will cause slow downs or problems when more and more information are added to the database.
Hmm so all your server side code does is read your database and covert it directly to JSON? Here’s what I would be worried about
Security Risks — Everything is being sent over the wire now, the full structure and contents of your database can be acquired. You may become subject to some cross-site scripting or other attack. An attacker may acquire confidential information in your database. If this interface is bidirectional attackers may be able to modify or corrupt your database more easily then if you had a better interface.
Poorly defined interface — Design the interface between the server and client so that you’re working at the right level of abstraction. By simply transcibing the database over to javascript, your interface may not be accurately describing whats happening in appropriate vocabulary. You want names for actions reflecting what the javascript is actually trying to do. For example, instead of having a simple Json “AddUser” command, you now have a long string of Json queries for editing tables. If I was the javascript coder, I’d prefer a simple “AddUser” over having to figure out all the tables that needed to be modified.
Changes aren’t isolated — Every time your database changes a little bit you need to update the javascript code to deal with minor updates/renames. If the database structure changes significantly, then instead of having an isolated change with server side code, now all your javascript also has to change.
If it was me, I would think about the correct abstraction to provide the javascript code from the server code, this would both help to manage security and readability in a maintainable way.