• Resolved ace0930

    (@ace0930)


    I have a form in my custom menu page ( admin ), and I would like to save the value from the form somewhere.

    I have tried to save the data into the database, but I find this method a bit time-consuming ( create table ) and it causes some security concerns when connecting to the database.

    So far I have created a class and I save the data into the properties by this method with preg_replace to replace the properties value in the class.

    Is there any expert or experienced developers who can tell which method is better here and why?

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    The best solution depends on what you’re saving and how you plan to use it in the future. Generally speaking, writing to a file is much more inefficient. It’s usually only used to save large amounts of data which will likely never need to be accessed again except maybe one more time. Creating an export file for example.

    For data that’s less voluminous or will need semi-regular access, saving in a database is superior. A DB can retrieve random data much much faster than file access can. A DB can quickly pluck out data you want using complex relational properties that would be very difficult to do with file access. Creating a table typically only needs to be done once, so I’m unsure how it’s time consuming. In many cases you can use existing WP tables to save data in, so it may not even be necessary.

    Assuming you use a good strong password for your DB user, a properly configured DB server should be very secure. It could be configured to only accept requests from your web server, so outside access attempts would be futile. Then it’s as secure as the web server is. Focus on making the web server secure and then the DB will be equally secure. Keep good backups and there’s no cause for concern. Data saved in files would be no more secure anyway.

Viewing 1 replies (of 1 total)
  • The topic ‘Proper way of saving data’ is closed to new replies.