Basic ORM strategy in PHP: How could it look like? - php

Basic ORM strategy in PHP: How could it look like?

Without wishing to cause offense, I’d suggest that you scale this back quite a bit - you seem to be biting off a lot more than you can chew considering your familiarly with the language and general OO practices. (I'm basing this on some other questions you've asked - not just this one.)
As an general suggestion, I think you'd save yourself a lot of pain by having a thorough read up on object orientation in general (design patterns couldn't hurt as well) and then thinking about the problem afresh.
Alternatively, if you post the problem you’re trying to solve (rather than discussing issues with a solution you’ve decided upon) you might get more traction.
Hope this helps.

I think you should look at existing PHP ORMs for an example:
Doctrine
Propel
Outlet
Sprig (Currently in development by the author of the Kohana framework)
Those are the main ORMs people use, listed in order of popularity.

Related

Comparing php framework - by their unique features

I saw many many compares with php frameworks, but they are just rather general - OOP supported, MVC supported... there are really unique features which distinguish them. Symfony has flash variables, Zend has tons of classes for general purposes.
Anybody knows such compairing stuff?
Pick one you hear about, try it, and see what fits. Personally I've fallen for CodeIgniter, and just haven't looked into anything else as I haven't run into a limitation for my purposes.
Its really about picking the best tool for the job.
I'd say look into that table on Wikipedia that danp posted. I'd suggest doing some cursory research just by visiting the Wikipedia entries for a few of the top frameworks and pick one. The goal of a framework is to help the programmer to be more productive. If you have a good grasp of PHP and web programming in general, any of the frameworks will be a help.
If you are coming from a Rails background, I would suggest CakePHP or Lithium, since they share a tone of similarities with Rails. Hope this helps!
The problem with comparing unique features is that the unique features are mostly stuff you don't care about, otherwise it would already be implemented in the framework. I'd recommend you to go to forums, both people criticising it and raise it to the skies, see what their cases are and why their framework is a fit for them.
Don't just look for what a framework does, but what it does right.

How towork with propelorm

I am new to propel,any one can explain me about what is the use of it and how to integrate any framework with propel?
Well, since there is an entire website about Propel, full of documentation and the like, I'll bet they can.
You bigger question, I think, is that you probably want to understand what the purpose of an ORM is. In short, it is a way of mapping between a relational database and an OOP framework, but Wikipedia has far more information, so you might want to start there.
EDIT
You mentioned in a comment that you'd like to combine this with CakePHP. Well here's how: don't unless you already know how to combine them. CakePHP has its own ORM system, so there really is no justifiable use case for having both (legacy code is not excuse -- just choose one!). If you're using Cake, use Cake and rejoice (you can have tea and skip on the or death)! If you're using Propel, use Propel and go somewhere.
For such a general question, I'd point you to the official site - http://www.propelorm.org/
Their documentation is surprisingly robust.
Have you tried their website? Here is a screenshot, this should do it. it's amazing what Google is capable of, don't be afraid to use it.

Mysql php class recommendation

I have been using ezSQL for the last few years but feel it is outdated. Though I like the simplicity and I like the file based caching ability with json, for small result sets that is.
So starting a new project I was looking for suggestions on a better mysql class for php. I know the db will only be mysql so portability is not a requirement. I read about mysqli extension, pdo etc but just dont know which one would be best for my situation. The site does a lot more reads than writes, though there are times where there are a lot of writes in the admin tool to the db. I looked at doctrine but dont know if that is too "bloated" for what I need. Hopefully this isnt to vague. Any suggestions?
EDIT
The site isnt small, I would consider it a high traffic site with a lot of db queries.
What don't you like about ezSQL? I often wish there was something like it for other protocols/languages I encounter. Every syntax should be written like ezSQL, in my opinion.. It describes the operation to be performed, in as few words as is possible, in the clearest and most logical order. Do you actually have performance problems, or are you just worried that something better has come along? I agree that ezSQL is rarely mentioned, but I have yet to find anything that matches it's simplicity, conciseness, and function...
From what I know of ezSQL (via it's wordpress pendant) I would consider Doctrine as well as too much for the moment because it's a complete data mapper for the database whereas you might be more looking to how to move away from your recent use of ezSQL which I think is a good idea.
Bascially you might be interested in a data-access abstraction layer. That could be PDO as it's build in into PHP. Even if you don't need to change the database server, it will give you defined interfaces how to query and access the data.
As you build the site from scratch, I can suggest you consider using some lightweight framework. A good introduction in my eyes is When Flat PHP meets Symfony which shows how a webapp can generally benefit from patterns and a flexible design.
From experience:
Doctrine - very easy to use I love doctrine query language - I never had to do initial setup though so im not sure how hard it is. It has very good community and lots of tutorials.
Propel - used for a bit. Does the job, very similar to doctrine. However, the documentation is very crap and community is very slack. I found that when I didn't know something it was quite hard to find an answer and often I had to post on Google forums.
Note: If you are starting from scratch you might want to look at some of the frameworks such as symfony+doctrine is a good combination, makes development a lot easier.
Links:
- http://www.doctrine-project.org/
- http://www.propelorm.org/

Avoiding Bad PHP Coding

There is a lot of books and tutorials about php that are completely different from each other.
How can I choose the right way? Is the only way is test with xdebug or phpUnit or benchmark?
Have a look at the slides and the tools given at
Quality Assurance in PHP Projects
Disclaimer: I am not affiliated with Sebastian Bergmann or thePHP.cc - they just happen to be major influence on the code quality topic in the PHP world, which is why I suggest this link.
General Best Practices
As code quality/readability/maintainability cannot be "benchmarked", I suggest reading books about proper code structuring and best practices.
Maybe Code Complete book from Steve McConnell?
Consider using Suitable Patterns and Frameworks
It's also worth mentioning the use of a well defined pattern like MVC and build your project with some Framework like Zend, as this will encourage you to put each piece of code where it belongs.
xdebug is a very powerful tool and can help you a lot.
You will be able to see in your development server (and not an ideal server) what is happening with your code!
If you like to improve your php code here are several advices:
do not use procedural programming, use oo
use some framework like kohana
use patterns every time
read some books about java oo programming (good book: beginning java objects 2 edition)
Aldo it is different language, java teaches about good oo code and patterns.
do not use functions with cyclomatic complexity>20
Most programmers use complex hierarchical associative array. They are hard to maintaine. avoid using complex structure of associatve array as DTO, try using classes.
use coning standards.
test driven development, unit tests. If your code can be tested with unit tests you are one step towards good code. Continuous integration is always welcome, but not always suitable in php, depending on the code and libraries you are uning.
use mvc, layers in you architecture
there are a lot more thinks, but keep reading and improve all the time
Regards
Get experienced. Once you have changed a switch statement with instanceof's a couple of times, you see the advantages of polymorphism.
Keep thinking critical of your own code. Keep thinking about how you solve things and be open to other ways.
Read code. Unfortunately, most PHP code is not a good example on how to write code, but you will learn something from it nevertheless.
Read a book. A book is often more in-depth and detailed than any article on the interwebs.
Download a well known open source project or framework like Zend. Then read through some of the code to see how they approach common tasks, and the general structure they use.

Qcodo vs. CakePHP vs. Zend [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I have some exposure to CakePHP and think it is a great framework.
Then, I run into this thing called Qcodo. It is another PHP Framework.
I've been hearing Zend alot. They all seem very neat, but I'm wondering what are differences between all these frameworks.
Before I waste too much time learning another framework,
does anyone know pros and cons of each framework?
They all seemed to have the general goal: making web application development in PHP easy, modular, and scalable.
EDIT
Found this interesting comparison result between CakePHP and Zend
I have never heard of Qcodo.
CakePHP is a full featured framework with a lot of automagic, but unfortunately it is one of the slowest frameworks out there. It also doesn't have official forums, and there really isn't that busy of a community. It tries to be a Ruby on Rails clone, but that just doesn't work so well with PHP.
Zend is impressive. It has a strong community and a corporate backing. It is very featured, but it is also very bloated (see that benchmark) so it has moderate performance. From what I hear though, you are able to use the components separately without using the whole framework, and can even use them with other frameworks!
I use CodeIgniter at work and I love it. It is by far the most newbie friendly framework, and with your CakePHP experience it should be a breeze. It has very good documentation that is thorough, clear, and well written. There are a few features that it doesn't have (such as an ORM) that other frameworks have, but CI has one of the most active framework communities I've seen. Since it's easy to write libraries for it, you can find a library to do pretty much anything you want to - ORMs, authentication, etc. To add to this, if you want an ORM for CI, I recommend DataMapper.
You may also want to check out Kohana. It's a spin off of CodeIgniter. It's strictly PHP5 and has an ORM and some more features. Haven't used it myself though, but I have heard good things.
I recommend reading the features of each and determining what you need and looking at code samples of the features you'll be using most.
Some frameworks may seem intuitive to you, but not to others. Selecting a PHP framework is a very personal choice IMO.
I've been using CodeIgniter myself after using CakePHP for some time. The main reason for switching was due to performance, but CakePHP has come a long way in the last few years so that's probably not a valid reason anymore.
[Edit: Apparently, it still has performance shortcomings, see post by ryeguy and comments.]
I've never found Zend to be intuitive and have never looked into Qcodo.
Wikipedia has a list of web app frameworks by language, you might find information to help you decide there as well.
I use both QCodo & Zend Framework
QCodo is a MVC framework of code generator, a lot of codes are ganerated from your database design, and produce ready to use Search & Edit Form for each of your database table. It also handle the database table relationship to pre-generate a set of methods for one-to-many / many-to-many relationship between tables.
Due to these codes were generated from your database design, all the codes were optimsed for each project. In short, It is a framework of database oriented
...................................................
Zend Framework is designed, as far as I know from the founder of this project), to decouple all the models, and indeed they are deploying a lot of ready to use models for different kind of project, from the Zend_ACL (access control list for authenication), to Zend _Search _Lucene, Zend _Service _Twitter, Zend _Service _Flickr, etc). And I think there will be for the future.
My vote for Qcodo! A while ago I did a research to what suited me best, and the result is qcodo, nowadays I can't do a project without considering to use qcodo, or at least his database handling part which is absolutely fantastic.
I think Simfony is the best PHP framework although I have not use it. I used mainly Qcodo/Qcubed but I am moving to Rails, this is why I find Simfony not bad. I tried Code Igniter and is not, it is simple to use, light (I suppose), but it does not have any scaffolding, but this might be changed now. As another guy said you can use an external ORM because CI does not have one by default. Zend Framework has a very modular architecture and has many libraries. I used Zend_ACL but permission inheritance was a pain so I did my own implentation, Zend_Lucene queries did not found the data I needed... ZF is a very low level framework and it needs an ORM too. I had a look at CakePHP but I found it its database interface not at the level of Propel, Qcodo and Doctrine, but I think the you can use your own library.
I usually want in a framework:
ORM and object wrapping the real row in the database ($objUser->Name = 'Jack')
MVC - most of the are MVC
Code generators (Qcodo is fantastic to code generate from the database)
Front controller, routing and url friendly (Qcodo does not have one)
Clean template (Qcodo has $objLabel->Render(); not real tags)
helper methods like link_to, image_tag etc (Simphony and Ruby on Rails)
Database migration to keep track of DB changes
integrated testing framework to test the real application, not few isolated functions (Rails do that and may Simfony)
The community and popularity of the framework.
Most of the advanced PHP developers I met use Simfony, but this is from my personal experience only.
Concluding, I would use Simfony bit I strongly suggest to try Rails using Ruby or JRuby.
Determining the best framework should be a project-by-project decision. If you have a big database using the innoDB engine and lots-and-lots of relationships between tables, check out QCubed (Qcodo). I've seen no framework that handles complex ORM relationships - even reverse relationships with ease! It's also quite fast at handling complex queries (e.g. reverse relationship queries) - although performance in any framework depends largely on the coder's ability to write efficiently.
If you're building a CMS, then you'll want Zend or Symfony for the MVC capabilities. QCubed/codo supposedly is MVC based, but it doesn't seem as clearly laid out as Zend. QCodo also DEPENDS on never changing the structure of your database - One can manage, but it's a real pain to add new fields to a DB table once a site has been launched because it auto-gens custom classes for each table.
I use CodeIgniter mainly because it had really good documentation and has a reputation of being easy to use. Also, Rasmus said it was his favorite, which is admittedly a lame reason, but I've had no complaints.
Don't ignore Symfony, it rocks. I'd say its biggest strengths are a consistent "go with the best practice" approach at every level, a vibrant community and excellent documentation.
I;m using QCubed, the successor to QCodo. Its simply the best you can get out of an Open Source PHP framework. Is quite fast if you know how to make it work. The only downside is that the documentation is lacking. However, the examples site is great. Start using it and I bet you'll have a lot of peace! :)

Categories