Aloha,
I just recently started programming in PHP and have a basic naming convention question. I've read a lot of PHP coding standards after reading this post. It made perfect sense to me, since I already prefer to use camelCase when naming variables. Since I'm going to be working with MySQL, I also read up on Database naming conventions. There's a lot varying preferences, but it seems like as long as you're consistent, it's ok. One thing I seemed to notice, however, is that most Database naming conventions say to start attributes with an Upper case letter, whereas in PHP (as well as most programming), variables should start with lower case letters. I'm going to be using the MVC model with DAOs and VOs. I really want my VOs to reflect my database tables, but the casing of the first letter is conflicting. Should I leave the casing mis-matched, or change one so they're both the same? How do you guys do it?
Thanks in advance,
Frank
Function names use underscores between words, while class names use both the camelCase and PascalCase rules. PHP will prefix any global symbols of an extension with the name of the extension.
Though these vary somewhat between SQL “flavors”, SQL columns and table names should begin with a letter, not end in an underscore, and should contain only alphanumeric characters. Column and table names should not contain spaces.
Database names must only consist of the letters a to z (both lower and upper case allowed), the numbers 0 to 9 , and the underscore ( _ ) or dash ( - ) symbols. This also means that any non-ASCII database names are not allowed. Database names must always start with a letter.
I would suggest lower case used with underscores for database naming as this will make your code more flexible.
Example:
Say you using MySQL as the database and name a table FooBar. Now the client wants to switch to PostgreSQL as an alternative database, this causes your table name to become a problem since postgres uses lower case naming or wrapped in double quotes.
MySQL query syntax:
SELECT * FROM FooBar
Postgres query syntax:
SELECT * FROM "FooBar"
If you had followed a generic naming scheme you could use one query for both
SELECT * FROM foo_bar
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With