posted 4 years ago in CUBRID Apps&Tools category by Esen Sagynov
Have you ever wanted to write a code and never think about the database schema part until you have a somewhat working prototype of your app? Or are you tired of constantly modifying your DB schema to serve your newly added code of your application? Today we will review RedBeanPHP which provides an easy-to-use Object Relational Mapping (ORM) for PHP to allow developers to forget about a database design and instead focus on app development. RedBeanPHP is a great tool for prototype development!
Here is how simple it is:
$bean = R::dispense('email'); $bean->subject = 'Read this email'; $bean->date = date('Y-m-d H:i:s', time()); $id = R::store($bean); $email = R::load('email', $id); var_dump($email);
What this does is:
- Creates a new bean which represents a table record. The type "email" will later serve as a table name.
- Assigns values to the necessary attributes which will represent the table columns.
- Special types such as DATE and DATETIME will be stored as respective data types in a database.
- Calling R::store() will create a table in the database with the necessary columns to store the bean attribute values.
- To retrieve the record back from the database, call R::load() function.
This is all it takes. RedBeanPHP will automatically create the necessary table, if it does not exist already, will create columns and store the given values. Very simple! If later you decide to add more columns, simply assign a value to a new attribute for the same bean, and store the bean. RedBean will alter the table schema to reflect the changes. You do not need to even open the SQL Client to adapt your database schema to your code changes. You start the app development immediately without thinking about the database design part.
Here is what you can do more with RedBeanPHP:
- Focus on app development, forget about database structure.
- No configuration is required. Only one file (84KB).
- Create tables, columns, indexes, and foreign keys (one-to-many, many-to-many, many-to-one) automatically.
- Automatically convert columns based on input data, except for special types. It comes with an Optimizer to further adjust columns for specific types.
- Provides Model class for input data validation, Aliases to use a certain bean (a database table) as a base for multiple objects (eg. both author and editor can be stored in a table users).
- Freeze mode to finalize database schema changes.
- Easy syntax to lookup the records. You can mix SQL with PHP when building queries.
- Provides nice implementation of Dependency Injection.
- Supports Database Transactions.
- Provides BeanCan Server to easily process client AJAX requests.
- Supports CUBRID, MySQL, PostgreSQL, and SQLite databases.
- Integrated into multiple popular PHP Frameworks. Plays well with CodeIgniter.
- Like many frameworks, RedBeanPHP provides functions to bulk import and export input data.
- Provides NoSQL-like syntax:
- Like NoSQL, you can just store objects right away without defining a schema
- Like NoSQL, no configuration is required
- Like NoSQL, RedBeanPHP has better performance than most classic ORMs
- Provides very exhaustive manual on how to use RedBeanPHP and its various functions.
We have reached out to RedBeanPHP developer, Gabor de Mooji, to receive his feedback on how easy it was to get started with CUBRID Database. Here is what Gabor told us:
- CUBRID SQL is pretty straight forward as well and easy to use. Seems to conform to SQL standards pretty well.
- Performance is good, especially compared to Oracle and MySQL
- I like CUBRID Manager and its features (easy backup tools, scheduling etc)
- I like the powerful SQL features like the click counter, collection support, extensive string/date functions
- I like the Java integration, would be awesome if you could do something like that for PHP as well given that PHP is the no. 1 web development language
- I like the type conversion system (Postgres doesn't do this very well)
On the other hand, the RedBeanPHP dev has reported several issues he has encountered during his introduction to CUBRID:
- Installation (on Linux in my case) was straight forward but has to be performed by hand because CUBRID has not been included in PHP (yet). [Gabor meant that CUBRID PHP API is not distributed together with PHP Engine itself.]
- I am afraid that CUBRID wont be used by many newbees because it might be a bit challenging to install (It's not hard but PHP is known to be used by less experienced developers). I recommend to offer a complete php distribution on your website for Linux, Windows and OSX. A LACP stack ? Given the concerns about Oracle/MySQL this might help to boost popularity of CUBRID.
- Part of the charm of PHP is that it scales from newbees to facebook-sized corporations. Especially entry level developers are inclined to stick with MySQL simply cause it ships with PHP, XAMPP and easyPHP. Some of them never even heard of Pecl. CUBRID is not hard to install but to make it really popular you need to do more, offering an easyPHP like distribution of PHP bundled with CUBRID would improve 'awareness'. It's just an idea.
We are very glad to receive such constructive feedback from Gabor. He has raised important aspects about how to reach the end users. We will look closer into how we can integrate CUBRID Database into existing LAMP-like stacks. In the meantime, if any one of our blog readers is from LAMP-like stack development community, please let us know. We will be to cooperate!
Now go to this RedBeanPHP tutorial to see a step by step detailed tutorial on how to retrieve and store Gmail emails using PHP IMAP and RedBeanPHP.
Information for our readers!
If you develop an open source application and would like to become a CUBRID Partner by supporting CUBRID Database in your project, contact us by email email@example.com. In your letter please provide an overview of your software, project links, and your statement on behalf of your project. We will be very glad to have you onboard!