Constants and mysql best practices

I currently have a list of defined constants and a function that regex'es every pulled MySQL row and searches for things like CLIENT_NAME, LOCAL_API_ADDRESS and automatically changes it.

// several fields define ('CLIENT_NAME', '...'); define ('LOCAL_API_ADDRESS', '...'); ... 

The fact is that when my application gets bigger, I feel that it is quite inefficient and is related to line losses (forgetting about regex here or there).

How do you guys handle this?

+4
source share
3 answers

MySQL had User Variables since v3.23.6 , but they ...

... are connection specific. That is, a user variable defined by one client cannot be seen or used by other clients. All variables for a given client connection are automatically freed when this client exits .

In fact, in MySQL there is no convention for storing constants.

You can store the values ​​in a table, but things like MySQL REGEXP may require dynamic SQL (using MySQL approved instructions) to take advantage of the setup.

+4
source

Honestly, if you don’t do this abnormally many times, it’s not so bad for that. Many template modules use regular expression search and replace. Most of the overhead is loading the regex engine for the first time. A few queries are not that expensive.

You better make sure your REGEX is optimized.

+4
source

Use caution when processing data. If you retrieve data from a database that overrides certain constants, you may run into security problems!

+2
source

Source: https://habr.com/ru/post/1313332/


All Articles