I am testing out PHP (Codeigniter) and Mongo (library by alexbilbie).
I a new to MongoDB so I got a few starting questions.
Is the library by Alex ready for production use? Can I use all mongodb features?
Is Alex library the best for Mongodb to Codeigniter use?
Do I have to use chained queries like this?
$this->mongo_db->where(array('firstname' => 'Michael'))->get('users');
I want each "part" on a separate row like this:
$this->mongo_db->select('*');
$this->mongo_db->from('users');
$this->mongo_db->where(array('firstname' => 'Michael'));
$query = $this->db->get();
Thank you!
$this->mongo_db->where(array('firstname' => 'Michael'))->get('users');
This is very similar to how the driver operates which is likely why it was chosen. The syntax you're looking for is basically an SQL variant. While possible, this is not generally how it's done with MongoDB as MongoDB doesn't use SQL.
Is the library by Alex ready for production use? Can I use all mongodb features?
In terms of production-readiness, you'll have to run your own sanity checks. MongoDB is backed by a well-funded company (10gen) and the PHP driver is maintained by them. So you should be good there.
For the library, all of the commits have been performed by one maintainer. It's probably in production being used by him, but the code has zero unit tests which is not a great sign.
The wiki would seem to imply that not all features are covered. He even has "maybe" written beside things like "add user".
Is Alex library the best for Mongodb to Codeigniter use?
This is very subjective, how many MongoDB+Codeigniter libraries have you found?
Related
Maintaining database views in mysql is sometimes cumbersome. When you change a referred table you have to alter the table and there is no clean way to do that in migrations (DB::unprepared()). I guess using query scopes in models is more maintainable. Isn't it? Does it has negative effect on the performance.
I don't know how big your project is and I don't have many elements to judge this situation perfectly.
However, working with views means depending on the underlying database system. Obviously it has its pros and cons, but I would prefer to decouple my software components.
What if you change, in the future, switching from MySQL to MongoDB?
Maybe, you could use a cache system, like Redis or Memcached (and Laravel already has a ready-to-use service for it).
As I told you before, I am making this suggestion basically because I think about the software scalability and components decoupling.
Here you can learn about the basic use of the Cache Service: http://laravel.com/docs/5.1/cache
Also, if you have some confidence with design patterns, you can implement a really elegant solution using some stacked repositories alongside the decorator pattern.
You can find some interesting articles about the topic here:
http://culttt.com/2014/02/03/laravel-4-cache-service/
http://culttt.com/2014/04/23/decorator-pattern/
Yes, they're about Laravel 4 but the concept can be easily adopted in a Laravel 5.* project.
Hope it was useful!
EDIT: as I told in the following comments, if you don't want to start with something like Redis or Memcached, you can always use the filesystem-based Cache.
I'm looking for a good php framework with support for handling database migrations. Ideally I would like to be able to run a command that generates a migration script, one that updates the database with changes and can handle rolling back those changes. Is there anything out there that does this?
The Doctrine project supports migrations - http://www.doctrine-project.org/projects/migrations/2.0/docs/reference/introduction/en
Hmm, that documentation is a bit lacking, at least in the introduction. Hopefully it gets better as it goes on.
Whilst most popular in Symfony, this can easily be integrated into other frameworks or even used on its own.
Promising, but not yet have a stable version : https://github.com/fuel/fuel
There is a new php framework called Laravel and it has migrations the same way as ruby on rails. It seems so pretty!
You can find it at http://laravel.com/
Migrations Docs
In addition, the framework introduces the idea of bundles, what can give to your project a great modular view.
If you try it, tell us your experience! :)
symfony - http://www.symfony-project.org/
In symfony you can write database schema using ORM like Propel, it is independant from database driver. If you have a database already, you want to migrate to a different db, I think you can dump the db, change the db config, and re-import it to the new db. (though I have not tried it myself.)
There are much php framework over there that can use any database. For example Zend, Ci, Cake and many others. One thing you should do is change database type that's usually stored in configuration file. And then migrate your database manually. No framework that can generate migration script automatically. U can also use ESF for database migration
Hey everyone. I'm looking for a good Active-Record like data abstraction layer to hook into MongoDB for my PHP based website. Currently, I'm developing on Zend Framework, if that makes a difference. Can you give me a good suggestion?
Thanks,
Andy
Doctrine has a (beta) MongoDB Object Document Mapper. Havne't tried it yet, but I think it does what you are asking for.
Mandango is another Mongo ODM you might want to try out. According to this page on the Mandango site, it's faster than Doctrine's Mongo ODM.
(disclosure: I used to work with Mandango's lead developer)
I am a noob to PHP can anyone explain me whats Pear DB library with a practical use?
Thanks
http://pear.php.net - PEAR is a framework and distribution system for reusable PHP components.
EDIT(to the first answer):
Except DB abstraction packeges PEAR library contains huge amount of useful classes for work with XML, CURL etc. Full list of maintained packeges is available here.
BTW, PEAR stands for PHP Extension and Application Repository
The What:
Pear DB is abstraction layer. Its one of many framework components available from PEAR. What the heck is that? Its a layer/interface between PHP and the db provider (MySQL, MSSQL,Protege) . So, it handles calls to multiple types of db providers in pretty much the same way to your PHP application. Your application layer doesn't have to concern itself with the details of calling individual providers.
Pros:
Portability. Allows you to write your db interface code once and have it work with multiple providers.
Encapsulation. Makes many db calls a bit simpler to make.
Cons:
Performance. It will generally be a bit slower than calling php db commands directly.
Nutshell:
Its good to use it when you can.
Its just a database abstraction library. ALlows you to connect to different kinds of databases (MySQL, PostgreSQL) using a consistent API.
Most of my experience is on the MSFT stack, but I am now working on a side project, helping someone with a personal site with cheap hosting that is built on the LAMP stack. My options for installing extras are limited, so I'm wondering about how to write my data access code without embedding raw queries in the .php files.
I like to keep things simple, even with .NET. I generally write stored procedures for everything, and I have a helper class that wraps all calls to execute procedures and return data sets. I'm not looking for a full-blown ORM, but it might be the way to go and others who view this question might be looking for that.
Remember that I'm on a $7/month GoDaddy account, so I'm limited to what's already installed in their basic package.
Edit: Thanks rix0rr, Alan, Anders, dragon, I will check all of those out. I edited the question to be more open to ORM solutions, since they are so popular.
ActiveRecord seems to be the state of the art at the moment. I can't recommend any good PHP frameworks for that though. I tried Propel which, while nice, is not easy to set up (especially on a host that you can't install anything on).
Ultimately, I rolled my own ORM/ActiveRecord framework, which is not too much work and very instructive. I'm sure other people can recommend good PHP frameworks.
Take a look at the Zend Framework, specifically Zend_Db. It has a Database Abstraction layer that doesn't require anything other than the MySQLi extension to be installed and isn't a full-blown ORM model.
Maybe Doctrine would do the job? It seems to be inspired by Hibernate.
rix0rrr hit on it a bit, in that many tools are a pain to set up. Of course, I have my own solution to this problem that has been working quite well for the past few years. It's a project called dbFacile
I also wrote a bit of a usage comparison of the tools I found a few years ago. It's incomplete, but might give you a good starting point.
You mentioned that you don't want to embed raw queries but you don't want ORM, so I'm a bit confused about the middle ground you're hoping to find. I also have an ORM project that aims to require minimal setup and great ease of use.
The only requirement for my projects is PHP5.
I would try a framework. Zend Framework has been cited. Symfony seems interesting. It's based on ideas from Ruby on Rails.
You could also take a look at Prado. http://www.pradosoft.com/ It uses Active Record and DAO. Also if you use .Net then some of the formatting and conventions are similar.