Answer the question
In order to leave comments, you need to log in
How do you name your tables and fields in the database? CamelCase, camelCase, camel_case.....?
Actually a subject. What rule do you follow for naming tables and fields in a database?
Is there any accepted/approved naming standard in this case?
Answer the question
In order to leave comments, you need to log in
Only snake_case . And for tables, and for fields, and for indexes, and for stored procedures.
The main problem with the under_score style (using yii2 ActiveRecord as an example) for me personally is that it turns out to be a mess - dynamic attributes for classes are camelCase, and attributes from the database are under_score. If you can remember this in your code and explain it to yourself with some logic (if I see under_score, then the attribute came straight from the database, and cameCase is a dynamic attribute generated by php methods), then for users of your service API (if you have an API, of course) you do not explain such a suspicious difference in the naming of object attributes in any way - and you will be ashamed when generating help for your API. What to do? Apparently, suffer from camelCase in the names of the columns in the database (I personally consider them less readable than _) - but there is nowhere to go, you can’t argue against PSR.
Came to the option:
tables and schemas - Camel_case
fields and functions - camel_case
For 14 years of programming in php, js, html, css, mysql, I have tried all the naming styles of compound names: "camelСase, under_score, hy-phen". Now, wherever possible, I write compound names in lower case, separated by a hyphen, that is, hy-phen.
These are filenames, urls, array keys, html attributes, etc. This also includes database table and column names, you just need to use backticks. Example: `hy-phen`.
In PHP and JS, hyphens cannot be used in variable and function names, so I use camel case notation (camelCase) there.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question