tags:

views:

572

answers:

5

I am mainly looking for good development practices specially when working in conjunction with mysql. I searched through the questions but could not find any related questions. I would appreciate if some one share their practices and wisdom gained through experience.

Apart from some coding standards, I am also looking for design standards and common architectural practices.

Background: I started my career with Java, and over the years I moved to C#/.NET space. I have been practicing architect for over 3 years now. Just added this to give some idea to people.

+1  A: 

Zend Framework's "Coding Standards for PHP" is good starting point. Check also this post.

raspi
+6  A: 
  • Use a coding standard.
  • Use unit testing. PHPUnit and SimpleTest are the major xUnit systems in PHP.
  • Be object oriented.
  • Use version control. Any version control, just use it.
  • If applicable, use a framework. Zend, CodeIgniter, Symfony, and CakePHP are the major ones.
  • If no framework, at least use an ORM. Propel and Doctrine are the major ones.
  • Document. Heavily. Use PHPdoc or similar.

There are a wealth of tools out there for PHP. Please use them, and write good maintainable code. You'll make everyone happier.

Kalium
+2  A: 

Use PDO or mysqli. Using one of these will give you prepared statements, which are safer and more efficient. I can't believe how many examples and tutorials I see using the ancient mysql interfaces. PDO would also make it much easier to switch to a different database system, should you decide to try postgres for instance.

You might look into using Doctrine (http://www.doctrine-project.org). It has a bit of it's own learning curve, but provides very convenient functionality. The handiest parts, for me, are the table creation/test data loading functions. Personally, I prefer to write my own SQL and execute it with PDO, and not use an ORM much in production.

Mainly, learn about SQL and MySQL. http://www.kitebird.com/mysql-book/ this book is excellent. The PHP aspect isn't very intense; PDO takes care of most of it.

Alex JL
+13  A: 
Noah Goodrich
I like how you warn for template engines. I never really understood why people would throw a template engine into a language which itself was designed as a template language.
Pim Jager
Hi Gabriel, Thanks for the detailed answer. I really appreciate your thinking. I am very familiar with all the design patterns. I started my career with Java and then eventually I moved to C# and ASP.NET world. I have used most of the design patterns where appropriate. Now as an architect, I want to put some good practices and coding methodologies in place as I have some php apps along with .net apps.I don't want to impose the same restrictions on PHP for the reasons you mentioned above.
CodeToGlory
so are you saying using templates like SMARTY is just a waste of time and energies?
CodeToGlory
I"m suggesting that you had better have very valid, very specific reasons to use one. The only real reason I've seen thus far is that your template designers aren't competent to use PHP. And if that's the case maybe you need new designers? Other reasons include restricting the available functions, but this just requires some discipline. And Smarty's caching ability but there are other ways to accomplish this and probably do it better. :-)
Noah Goodrich
A: 

Your from a Java background, and much of the OO stuff in PHP is very Javaesque. This means many of the design patterns you (hopefully) learnt in Java also apply (to a lesser extent) in PHP. An example for database access would be the DataMapper pattern.