views:

91

answers:

5

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

A: 

do it like you like it, but, as you said yourself:

[...] as long as you're consistent, it's ok.

i would prefer using the same casing for both and start with a lower-case character.

oezi
A: 

I prefer to use all lower-case in names of tables and columns and whitespaces are replaced for underscores. Name of table in singular of model name. It usually helps to convert database structure to PEAR standard of model.

class User extends MyActiveRecord
{
   public function getFirstName()
   {
     //...
   }
}

SELECT * FROM user WHERE first_name LIKE 'Bill'

Foreign keys as "some specific info" _ "foreign table name" _ "foreing column name". It helps to find out, which table we link by foreign key.

SELECT * FROM post LEFT JOIN user ON post.author_user_id = user.id
Aliaksei Shytkin
Thanks everybody for your input, you've definitely helped me come to some conclusions. I have decided to use lowercase with underscores for my database naming.
LeTanc
A: 

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
Phill Pafford
A: 

Ya, for Database and table, everyone prefer underscore. Few likes all uppercase and few all lowercase. But if Phill is correct then I will vote for all lowercase for DB and table.

Satya Prakash
+2  A: 

Here's how Zend operates:

http://framework.zend.com/manual/en/coding-standard.naming-conventions.html

Andre