Archive for December, 2007

Dec 29 2007

Posted by coen under PHP

One step at a time

Some time ago I wrote about some great plans for writing an or-mapping. Well, today, I actually made some progress!

Before I started to write on this code, I divided it in three parts:

  1. Creating Objects
  2. Updating Objects
  3. Deleting Objects

I finished a test version of the first part today. Basically, this is how it works: There is a class Object that should be extended by every class that has to be in a database. If you create a class extending this one, it will also be created in the database (if it doesn’t exist yet) as a table. For example, see this class:

 

/**
 * foo
 * bar
 * @table_name=__TEST__
 *
 */
class Test extends Object {    
     /**
     * @nullable = false
     */
    private $firstname; 

    private $lastname; 

    /**
    * @type = string(12)
    * @nullable = false
    */
    private $dateofbirth; 

    private $city; 

    function __construct() {
       parent::__construct();
   } 

    public function getFirstName(){
   	return $this->firstname;
   } 

    public function setFirstname($firstname){
   	$this->firstname = $firstname;
   } 

    public function getLastname(){
   	return $this->lastname;
   } 

    public function setLastname($lastname){
   	$this->lastname = $lastname;
   } 

    public function getDateofbirth(){
   	return $this->dateofbirth;
   } 

    public function setDateofbirth($dob){
   	$this->dateofbirth = $dob;
   } 

    public function getCity(){
   	return $this->city;
   } 

    public function setCity($city){
   	$this->city = $city;
   }
}

Will result in this table:
table screenie


Pretty cool, huh? I still have to do some work, but the base is there. As you can see, you can also use some kind of annotations to set the information for the table and the columns in the database, but there are also default settings if they are omitted.
Enough for today, I’m going to celebrate my weekend and “Oud & nieuw”, as we call New Year’s Eve in Holland :) Soon more about this!

6 Comments »

Dec 18 2007

Posted by coen under PHP

Great plans

In the 2nd year of my study at the HU we learned about J2EE, in particular EJB. Happy with the general idea of never writing another line of SQL, we started doing our school projects with EJB. However it’s true that you don’t write SQL, there is EJB-QL, which looks a darn lot like SQL.
While I like the concept, I wonder if Java is the right language to use. I can’t help thinking about all the layers my poor code has to go through, and how can that ever be fast? Anyway, according to this test, Java is way faster than PHP, which was originally intended for the web (Wikipedia also has a nice comparison about this).

Strangely enough, at that time there was no framework or abstraction layer available for PHP, so I started building one myself. The idea was for it to work like EJB, and the result was satisfactory. Then doom hit me, because I lost all that code :( So now I’m going to start all over again, with a slightly different angle: I am going to write a framework that communicates with the Zend Framework, but with a little extra: the Zend Framework does not provide creation and automatic querying for your objects in the database, and that’s what will be the extra in my framework.

1 Comment »

Dec 17 2007

Posted by coen under Life&Cooking

Post number one

Some time ago I was thinking about writing down my daily and programming experiences on some kind of web-log. And there I am, writing my first blog entry. Problem is however, I tried this more than once, and it took me a really short while to stop again. I hope this time lasts way longer, because I also plan to use it as some kind of archive for myself (diary sounds silly, right?)
So, in good faith I say “good luck to myself” :)

4 Comments »