CodeIgniter Forums
Naming database columns and form inputs - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Best Practices (https://forum.codeigniter.com/forumdisplay.php?fid=12)
+--- Thread: Naming database columns and form inputs (/showthread.php?tid=78807)



Naming database columns and form inputs - motownphilippe - 03-13-2021

Examples in the CI4 documentation use snake_case for database column names. Indeed the default values 'created_at', 'updated_at' and 'deleted_at' support this convention. 

CI4 entities promote using the same names for html form inputs as database column names. Doing so streamlines filling the database from html forms. So the convention to use snake_case in column names will (should) lead to the same convention for naming form inputs.


Doesn't this conflict with using camelCase for object properties? For example using both conventions I need to know where an entity property came from: if it was loaded from database I need to refer to it using snake case, but if was created by code at runtime I need to refer to it using camelCase. I need to keep track of which it is. 

Is snake_case for column names a widespread convention? 

Are there good reasons for it? I would love to hear what they are. 

I would appreciate any advice, even a good article to read. I haven't found one in my internet searching. 


RE: Naming database columns and form inputs - InsiteFX - 03-13-2021

For PHP SEE:

PHP Standards Recommendations

Basic Coding Standard

Extended Coding Style Guide

For MySQL Database SEE:

MySQL naming - coding conventions: tips on mySQL database


RE: Naming database columns and form inputs - motownphilippe - 03-13-2021

Thanks. 
following these conventions leads to a conflict with CI4 entities. 
Say I have a database with a field name called "some_category
Say I then instantiate an entity representing a row from this table and call it $myEntity. 
To refer to some_category I will need to call:
Code:
$myEntity->some_category


This contravenes the standard I see (but haven't found written down) that property names must  be in camelCase.

Are we ok with this conflict?